Ruby-on-rails 如何用简单的形式定义动作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7507633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define action with simple form for?
提问by Rails beginner
I am trying to define the action "savenew" in admin/photographers controller.
我正在尝试在 admin/photographers 控制器中定义操作“savenew”。
I have tried this:
我试过这个:
<%= simple_form_for(:photographer_savenew, :action => 'savenew', :id => params[:id], :multipart => true ) do |f| %>
But the action in the form is still: /admin/photographers
但是表单中的动作仍然是: /admin/photographers
When it should be: /admin/photographers/savenew
什么时候应该: /admin/photographers/savenew
回答by Peter Brown
Is there a reason you're not using REST for this? It would make your life a lot easier and requires much less code. If you're set on using this custom action, you will need to specify the url and probably the method:
您是否有理由不为此使用 REST?它会让你的生活更轻松,并且需要更少的代码。如果您设置使用此自定义操作,则需要指定 url 以及可能的方法:
<%= simple_form_for @photographer, :url => savenew_photographers_path, :method => :post ... # etc

