简体   繁体   English

如何为具有重命名路径的嵌套资源编写simple_form?

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

I have a Band model and a BandMember model. 我有一个Band模型和一个BandMember模型。 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: 现在,我想为BandMember制作一个简单的表单,如下所示:

<%= 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 . 如果我的模型名称是Member而不是BandMember这将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方法的url选项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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