How do you handle single table inheritance in SimpleForm so a single helper handles all models?

余生颓废 提交于 2019-12-05 02:15:23

问题


We have a model "EventSession" which has several subtypes via STI, including "NetworkingEventSession" and "DiningEventSession"... we want to be able to handle all of them from one controller and one view in some cases, but simple form is looking at the objects when iterating through in simple_form_for @session and trying to use the networking_event_session_path helper, which we don't currently have defined, instead of the regular event_session_helper path, which would work fine and is what we want.

I could define new routes to get helpers for each subtype, all directing to the same path, but that will be very unDRY, and we may not always want them going to the main event session path... is there some way to override simple_form_for in this particular view to tell it explicitly what model/class to use?


回答1:


Specify :url=> networking_event_session_path in the simple_form_for.

Something like this:

<%= simple_form_form @session, :url => networking_event_session_path %>


来源:https://stackoverflow.com/questions/10607016/how-do-you-handle-single-table-inheritance-in-simpleform-so-a-single-helper-hand

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