Render partial from another model

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 12:43:58
tig

Very strange — if you write <%= render :partial => 'room_form' %> than rails will assume that it is app/views/calculator/_room_form.html.erb, but in case of <%= render :partial => 'rooms/room_form' %> it will assume that it is app/views/rooms/_room_form.html.erb

Watch your log — there you will see which partials were rendered

I know this question is old but I ran into the same problem and managed to solve it.

To be specific I too was following ryan bates complex forms examples.

My form was not rendering with the same error:

undefined method `reflect_on_association' for NilClass:Class

I commented out the add_child_link helper and the form rendered but upon submission I got:

ChildModel expected, got Array

After much headscratching I made one simple change that fixed everything:

-- form_for :project
++ form_for @project

That's right, just switching the symbol for an instance variable made it all work.

Hope this helps anyone else who gets stuck

The issue is that you don't have a room object defined when you're trying to add a child link.

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