actionview - Ruby on rails nested form model -
I'm trying to use auxiliary form_for nested rails, but I am getting the following error:
BlogPage (# 49,859,550) expected, array (# 31117360) found
here are my model objects:
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 Blog Page & lt; ActiveRecord :: Base # table configuration set_table_name "blog_page" # model configuration belongs_to: Blogs end
The Form I is generated (the unnecessary HTML left out): < / P>
& lt;% form_for: blog ,: url = & gt; {: Action = & gt; : Making} do Blog_form | & Gt%; & Lt;% = blog_form.text_field: Title ,: style = & gt; "Width: 400px"%> & 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"%> & Lt;% end% & gt; & Lt;% end% & gt; & Lt;% end% & gt; > { "Blog_pages" => { "content" => "This new blog entries is content."}, "Title" => "This is a new blog entry" "full" => "1"}, "authenticity_token" => "T1Pr1g9e2AjEMyjtMjLi / ocrDLXzlw6meWoLW5LvFzc ="} There is BlogsController making that action is executed: < / P> Class BlogsController & LT; ApplicationController def new @blog = Blog.new # This is the line where the error is thrown. Set up a page for #new blog so that the view is displayed properly @ Blog.blog_pages [0] = BlogPage.new @ blog.blog_pages [0] .page_number = 1 Reply Do not Do It. Format | Format.html # new.html ARB goes into the scene Format.xml {Render: xml = & gt; @blog} format.js {render: layout = & gt; Bad} end-end DRF @ blog = blog.new (param [: blog]) response_to do | Format | If @ blog.SaveRender: Action => : Show and Flash [: Notice] = "An error occurred while saving the blog entry." Render: Action = & gt; : End of the new end
I appreciate it if someone can help me with this. I am still new to the Ruby and can not solve the problem on my own by rail framework and googling.
Thank you.
have you seen it?
Comments
Post a Comment