Ruby 嵌套模型Rails 3.2.2的字段\u
我的Rails应用程序中有一些嵌套模型。 我有一篇文章有很多特点Ruby 嵌套模型Rails 3.2.2的字段\u,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,我的Rails应用程序中有一些嵌套模型。 我有一篇文章有很多特点 class Article < ActiveRecord::Base has_many :properties, :dependent => :destroy accepts_nested_attributes_for :properties end class Property < ActiveRecord::Base belongs_to :article end 还编辑了视图和_format
class Article < ActiveRecord::Base
has_many :properties, :dependent => :destroy
accepts_nested_attributes_for :properties
end
class Property < ActiveRecord::Base
belongs_to :article
end
还编辑了视图和_format.html.erb
<%= form_for(@article) do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<% f.fields_for :properties do |prop| %>
<div class="field">
<%= prop.label :name %><br />
<%= prop.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
但是没有办法出现。如果要创建新模型,则无法看到属性的任何输入字段
class Article < ActiveRecord::Base
has_many :properties, :dependent => :destroy
accepts_nested_attributes_for :properties
end
class Property < ActiveRecord::Base
belongs_to :article
end
我做错了什么?行的字段中缺少一个=。也就是说,它应该是:
<%= f.fields_for :properties do |prop| %>
您的字段中缺少一个=作为行。也就是说,它应该是:
<%= f.fields_for :properties do |prop| %>
就这样。非常感谢,不用担心。不要忘记,您也可以通过单击绿色复选标记来接受这一正确答案;提高你的录取率会让其他人在将来更愿意帮助你,就是这样。非常感谢,不用担心。不要忘记,您也可以通过单击绿色复选标记来接受这一正确答案;提高你的接受率将使其他人在未来更愿意帮助你。