Everything was working until I wanted to add a second collection_select in order to select the location that belongs to the company from the current user in my openings/new view. I read and tried different ways but still not working.
Jobdescription collection_select works well alone, but I do not know if the problem is from, even if I suspect the controller.
if you can tell me where the issue is, that would be very kind of you. Thanks.
My schema.rb
create_table "companies", force: true do |t|
t.string "company_name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "openings", force: true do |t|
t.integer "jobdescription_id"
t.integer "location_id"
t.date "ending"
t.datetime "created_at"
t.datetime "updated_at"
create_table "locations", force: true do |t|
t.string "name"
t.string "postalcode"
t.float "lat"
t.float "lon"
t.integer "company_id"
t.datetime "created_at"
t.datetime "updated_at"
end
Company.rb
class Company < ActiveRecord::Base
has_many :users
has_many :jobdescriptions
has_many :locations
end
Location.rb
class Location < ActiveRecord::Base
belongs_to :company
has_many :openings
geocoded_by :postalcode,
:latitude => :lat, :longitude => :lon
after_validation :geocode
end
Opening.rb
class Opening < ActiveRecord::Base
belongs_to :company
belongs_to :jobdescription
belongs_to :location
end
app/controllers/openings_controller.rb
class OpeningsController < ApplicationController
layout 'application'
def new
@opening = Opening.new
@jobdescriptions = current_user.company.jobdescriptions
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @jobdescription }
end
@locations = current_user.company.locations
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @location }
end
end
app/views/openings/new.html.erb
<div class='form-group'>
<label>Job desc</label>
<br/>
<%= collection_select(:opening, :jobdescription_id, @jobdescriptions, :id, :job_title, {:prompt => false}) %>
</div>
<div class='form-group'>
<label>location</label>
<br/>
<%= collection_select(:opening, :location_id, @locations, :id, :name, {:prompt => false}) %>
</div>