nested forms for 2 models in rails using dm-accepts_nested_attributes and dm-is-tree

≯℡__Kan透↙ 提交于 2019-12-06 08:39:48

attr_accessor :images_attributes in the Post model, allows the form to submit

However, the image is now not being saved, i.e. gets lost somewhere and isn't saved

The response I get from submitting the form:

Started POST "/forums/x/posts" for 127.0.0.1 at 2010-12-22 10:15:19 -0500
  Processing by PostsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"/cyeRIls9M..7U8eG1lXAJg8=", "post"=>{"istop"=>"parent", "content"=>"sdfgsdfg", "images_attributes"=>{"image"=>#<File:/tmp/RackMultipart20101222-874-bhvepi>}}, "commit"=>"Create Shout", "forum_id"=>"x"}
  SQL (0.054ms)  SELECT "name" FROM "forums" WHERE "name" = 'x' ORDER BY "name" LIMIT 1
  SQL (115.419ms)  INSERT INTO "posts" ("istop", "created_at", "updated_at", "forum_name") VALUES ('parent', '2010-12-22T10:15:20-05:00', '2010-12-22T10:15:20-05:00', '', 'sdfgsdfg', 0, 'x')
Redirected to http://localhost:3000/forums/x
Completed 302 Found in 123ms

I'm guessing the form is ok, but its not saving the image.

Adding

@post.images_attributes = Image.new

or some variation to the controller does nothing so I'm curious if I need to create some sort of hook in the Post model to save the image. I do not know at this point.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!