2012-03-26 11 views
2

私はRailsアプリケーションにいくつかのネストされたモデルを持っています。 記事の帽子にmnyプロパティがあります。Fields_ for Nested Model Rails 3.2.2

class Article < ActiveRecord::Base 
    has_many :properties, :dependent => :destroy 
    accepts_nested_attributes_for :properties 
end 

class Property < ActiveRecord::Base 
    belongs_to :article 
end 

そして今、私は私が

# GET /articles/new 
    # GET /articles/new.json 
    def new 
    @article = Article.new 
    3.times { @article.properties.build } 

    respond_to do |format| 
     format.html # new.html.erb 
     format.json { render json: @article } 
    end 
    end 

のcontrolerをeditetし、またそこに見ると_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 %> 

を編集した。しかしので私の見解では、これを編集したいです表示する方法はありません。私は新しいモデルを作成したい場合、私はプロパティの入力フィールドを見ることができません。

どうしたのですか?

答えて

4

fields_for行に=がありません。つまり、次のようになります。

<%= f.fields_for :properties do |prop| %> 
+0

それでした。どうもありがとうございます。 – Lailo

+0

心配はいりません。緑色のチェックマークをクリックすることで、これを正解として受け入れることもできます。あなたの受け入れられた率を上げることは他の人があなたを将来的に助けることをより喜んでするでしょう。 – Chowlett