title: Ruby on rails nested form model
body: <p>I'm trying to use rails nested form_for helper, but I am getting the following error:</p>
  
  <p>BlogPage(#49859550) expected, got Array(#31117360)</p>
  
  <p><b>Here are my model objects:</b></p>
  
  <pre><code>class Blog &lt; ActiveRecord::Base
    # Table Configuration
    set_table_name "blog"
  
   # Model Configuration
   belongs_to :item
   has_many :blog_pages
   accepts_nested_attributes_for :blog_pages, :allow_destroy =&gt; true
  end
  
  class BlogPage &lt; ActiveRecord::Base
    # Table Configuration
    set_table_name "blog_page"
  
    # Model Configuration
    belongs_to :blog
  end
  </code></pre>
  
  <p><b>Here is the form I generated (left out unnecessary HTML):</b>  </p>
  
  <pre><code>&lt;% form_for :blog, :url =&gt; { :action =&gt; :create } do |blog_form| %&gt;  
      &lt;%= blog_form.text_field :title, :style =&gt; "width: 400px" %&gt;  
      &lt;% blog_form.fields_for :blog_pages do |page_fields| %&gt;
          &lt;% @blog.blog_pages.each do |page| %&gt;  
              &lt;%= page_fields.text_area :content, :style =&gt; "width: 100%",
                  :cols =&gt; "10", :rows =&gt; "20" %&gt;
          &lt;% end %&gt;
      &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><b>Here are the parameters that are sent to the controller:</b></p>
  
  <p>{"commit"=>"Save",
   "blog"=>{"blog_pages"=>{"content"=>"This is the new blog entries contents."},
   "title"=>"This is a new blog entry.",
   "complete"=>"1"},
   "authenticity_token"=>"T1Pr1g9e2AjEMyjtMjLi/ocrDLXzlw6meWoLW5LvFzc="}</p>
  
  <p><b>Here is the BlogsController with the create action that gets executed:</b></p>
  
  <pre><code>class BlogsController &lt; ApplicationController
    def new
      @blog = Blog.new # This is the line where the error gets thrown.  
      # Set up a page for the new blog so the view is displayed properly.
      @blog.blog_pages[0] = BlogPage.new
      @blog.blog_pages[0].page_number = 1
      respond_to do |format|
        format.html # Goes to the new.html.erb view.
        format.xml { render :xml =&gt; @blog }
        format.js { render :layout =&gt; false}
      end
    end
  
    def create
      @blog = Blog.new(params[:blog])
  
      respond_to do |format|
        if @blog.save
          render :action =&gt; :show
        else
          flash[:notice] = "Error occurred while saving the blog entry."
          render :action =&gt; :new
        end
      end
    end
  end
  </code></pre>
  
  <p>If anyone can help me with this I would greatly appreciate it. I'm still pretty new to ruby and the rails framework and couldn't solve the problem on my own by googling.</p>
  
  <p>Thanks.</p>