Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sites_cultivars.rb #569

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
60 changes: 60 additions & 0 deletions app/controllers/sites_cultivars_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
class SitesCultivarsController < ApplicationController
before_filter :login_required, :except => [ :show ]

require 'csv'

# GET /sites
# GET /sites.xml
def index
request.format = :xml if params[:format].nil?

# We have a lot of params and they or may not have to be
# passed as conditions this is my way of adding them to conditions
# if need be

conditions = {}
params.each do |k,v|
next if !SitesCultivars.column_names.include?(k)
conditions[k] = v
end
logger.info conditions.to_yaml
sitescultivars = SitesCultivars.where(conditions)

respond_to do |format|
format.xml { render :xml => sitescultivars }
format.csv { render :csv => sitescultivars }
format.json { render :json => sitescultivars }
end
end

# GET /cultivars/new
# GET /cultivars/new.xml
def new
sitescultivars = SitesCultivars.new

respond_to do |format|
format.xml { render :xml => sitescultivars }
format.csv { render :csv => sitescultivars }
format.json { render :json => sitescultivars }
end
end

# POST /cultivars
# POST /cultivars.xml
def create
sitescultivars = SitesCultivars.new(params[:sitescultivars])

respond_to do |format|
if citationssites.save
format.xml { render :xml => sitescultivars, :status => :created }
format.csv { render :csv => sitescultivars, :status => :created }
format.json { render :json => sitescultivars, :status => :created }
else
format.xml { render :xml => sitescultivars.errors, :status => :unprocessable_entity }
format.csv { render :csv => sitescultivars.errors, :status => :unprocessable_entity }
format.json { render :json => sitescultivars.errors, :status => :unprocessable_entity }
end
end
end

end
5 changes: 4 additions & 1 deletion app/models/cultivar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ class Cultivar < ActiveRecord::Base
SEARCH_INCLUDES = %w{ specie }
SEARCH_FIELDS = %w{ species.scientificname cultivars.previous_id cultivars.name cultivars.ecotype cultivars.notes }

has_many :sites_cultivars, :class_name => "SitesCultivars"
has_many :sites, :through => :sites_cultivars

has_many :traits
has_many :yields

belongs_to :specie

validates :name,
Expand Down
3 changes: 3 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Site < ActiveRecord::Base

has_many :experiments_sites
has_many :experiments, :through => :experiments_sites

has_many :sites_cultivars, :class_name => "SitesCultivars"
has_many :cultivars, :through => :sites_cultivars

has_many :yields
has_many :traits
Expand Down
16 changes: 16 additions & 0 deletions app/models/sites_cultivars.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class SitesCultivars < ActiveRecord::Base
self.primary_key = "id"

validates_presence_of :cultivar_id
validates_presence_of :site_id

belongs_to :cultivar
belongs_to :site

comma do
cultivar_id
site_id
created_at
updated_at
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
end
end

resources :sites_cultivars

resources :citations do
member do
get :search_sites
Expand Down