简体   繁体   English

如何通过其他控制者的动作提交表格?

[英]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 . @categoryBoard实例,因此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.

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