pickhunter
pickhunter

Reputation: 356

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?

Upvotes: 2

Views: 239

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54892

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 %>

Upvotes: 3

Related Questions