0

一切正常,直到我想添加第二个 collection_select 以便在我的开口/新视图中从当前用户中选择属于公司的位置。我阅读并尝试了不同的方法,但仍然无法正常工作。

Jobdescription collection_select 单独工作很好,但我不知道问题是否来自,即使我怀疑控制器。

如果你能告诉我问题出在哪里,那你就太好了。谢谢。

我的 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

公司.rb

class Company < ActiveRecord::Base
  has_many :users
  has_many :jobdescriptions
  has_many :locations


end

位置.rb

class Location < ActiveRecord::Base
  belongs_to :company
  has_many :openings

  geocoded_by :postalcode,
              :latitude => :lat, :longitude => :lon
  after_validation :geocode
end

开幕式.rb

class Opening < ActiveRecord::Base
  belongs_to :company
  belongs_to :jobdescription
  belongs_to :location
end

应用程序/控制器/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>

4

1 回答 1

-1
<%= collection_select(:opening, :location_id, current_user.company.locations, :id, :name, {:prompt => false}) %>
于 2015-02-21T20:36:23.153 回答