在寶石的實現:https://github.com/arvindvyas/Country-State-Select如何解決Country-State-選擇gem未定義的方法問題?
當我去張貼招聘新的頁面顯示此錯誤的日誌
undefined method `country' for #<Job:0x007f8c07092320>
我試圖把
accepts_nested_attributes_for
在
工作模式,但沒有奏效。
有人有任何提示空閒?
工作模式
class Job < ActiveRecord::Base
belongs_to :user
belongs_to :location
accepts_nested_attributes_for :location, allow_destroy: true
default_scope -> { order(created_at: :desc) }
end
選址模型
class Location < ActiveRecord::Base
has_many :users
has_many :jobs
end
招聘新觀點
<%= simple_form_for @job do |f| %>
<%= f.simple_fields_for :location do |l| %>
<%= l.input :country, label: "Country", collection: CountryStateSelect.countries_collection %>
<%= l.input :state, CountryStateSelect.state_options(label: "State/Province", form: f, field_names: { :country => :country, :state => :state }) %>
<%= l.input :city, CountryStateSelect.city_options(label: "City ", form: f, field_names: { :state => :state, :city => :city }) %>
<% end %>
<%= f.input :name, label: 'Name', error: 'Name is mandatory' %>
<%= f.input :description, placeholder: '[email protected]' %>
<%= f.button :submit %>
<% end %>
一個
simple_fields_for
塊內什麼如果您在狀態和城市輸入行中將'form:f'更改爲'form:l',會發生什麼情況? –謝謝你簡單的石灰,我沒有注意到那個錯誤!現在工作。非常感謝你,如果你想創建答案這個問題讓我接受,那麼確定 – user8256239
確定的事情,不想讓它成爲一個答案,因爲我不知道它是否會有所幫助或者是否只是一個幸福的巧合。 –