[英]How to submit form with action from other controller?
I have form like this: 我有这样的形式:
<%= simple_form_for @category do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.input :parent_id, collection: @board.subtree, include_blank: false %>
<%= f.button :submit %>
<% end %>
@category
is instance of Board
so this :submit
tries to run create
action from BoardsController
. @category
是Board
实例,因此this :submit
尝试从BoardsController
运行create
动作。 Instead of it, I'd like to run create
action from CategoriesController
. 取而代之的是,我想从
CategoriesController
运行create
action。
How can I do this? 我怎样才能做到这一点?
只需添加url
选项。
<%= simple_form_for @category, url: category_path(@category) do |f| %>
This might help: 这可能会有所帮助:
https://stackoverflow.com/a/7136142/2128691 https://stackoverflow.com/a/7136142/2128691
so yours would look like: 所以你的样子:
<%= simple_form_for @category, :url => category_path, do |f| %>
...
<% end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.