在宝石的实现: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
确定的事情,不想让它成为一个答案,因为我不知道它是否会有所帮助或者是否只是一个幸福的巧合。 –