0
我有一個窗體,處理嵌套屬性(我認爲)。窗體不顯示它的嵌套屬性塊
A project
has_many graphs
,through project_graph
。
在我的表單中,嵌套屬性的代碼塊永遠不會呈現。有任何想法嗎?
查看
<%= form_for(@project, :html => { class: :form }) do |f| %>
<%= f.fields_for :project_user_graphs do |graph_form| %> <!-- this never renders -->
<p>How come this block never is executed? This wont show up.</p>
<% end %>
<%= f.submit class: "btn btn-primary" %>
<% end %>
模式
class UserGraph < ActiveRecord::Base
has_many :project_user_graphs
has_many :projects, through: :project_user_graph
accepts_nested_attributes_for :project_user_graphs, allow_destroy: true, reject_if: lambda {|attributes| attributes['user_graph_id'].blank?}
end
class Project < ActiveRecord::Base
has_many :project_user_graphs
has_many :user_graphs, through: :project_user_graph
accepts_nested_attributes_for :project_user_graphs, allow_destroy: true, reject_if: lambda {|attributes| attributes['user_graph_id'].blank?}
end
也許沒有關聯的實例。在你的控制器中,你是否做了類似'@project.project_user_graphs.build'的東西? – aceofspades