简体   繁体   中英

How to write simple_form for nested resources with a renamed path?

I have a Band model and a BandMember model. My routes definition is

resources :bands do
  resources :band_members, as: :members, path: 'members'
end

Now I want to make a simple form for BandMember like this:

<%= simple_form_for [@band, @band_member] do |f| %>
<% end %>

This throws an exception:

undefined method `band_band_member_path'

This would have worked if my model name was Member instead of BandMember . I do not wish to rename the model. Any ideas to get around this?

You can use the url option of the simple_form_for method:

<%= simple_form_for [@band, @band_member], url: your_url_helper_path do |f| %>
  # ...
<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM