1
因此,關於「未初始化的常量」錯誤的問題有很多,而且幾乎總是由於指定的關聯不正確(例如複數模型名稱而不是單數形式,錯誤地將關聯寫入模型等)。我的模特和形式看起來一塵不染,所以也許這是新事物(或者我是盲人)?關聯的未初始化常量的路徑
「用戶」有一個「移動」。一個「舉動」有很多「neighborhood_preferences」,並通過這個,很多「鄰里」。
型號:
class User < ActiveRecord::Base
has_one :move
accepts_nested_attributes_for :move, allow_destroy: true
end
class Move < ActiveRecord::Base
belongs_to :user
has_many :neighborhood_preferences
has_many :neighborhoods, through: :neighborhood_preferences
accepts_nested_attributes_for :neighborhood_preferences, allow_destroy: true
end
class NeighbhoodPreference < ActiveRecord::Base
belongs_to :neighborhood
belongs_to :move
end
class Neighborhood < ActiveRecord::Base
belongs_to :city
has_many :neighborhood_preferences
has_many :moves, through: :neighborhood_preferences
end
查看:
<%= simple_form_for(@user, :html => { class: :form }) do |u| %>
<%= u.fields_for :move do |m| %>
<div>
<%= m.label :start_date %>
<%= m.date_field :start_date %>
</div>
<div>
<%= m.label :end_date %>
<%= m.date_field :end_date %>
</div>
<div>
<%= m.label :min_price %>
<%= m.text_field :min_price %>
</div>
<div>
<%= m.label :max_price %>
<%= m.text_field :max_price %>
</div>
<%= m.association :neighborhood_preferences %>
<% end %>
<%= u.submit "Save Changes" %>
<% end %>
ahahah殺了我的感謝。 –
你打敗了我:-) –