简体   繁体   English

提交表单中动态创建的表

[英]Submit a dynamically created table in a form

I have a dynamically created table inside a form_for . 我在form_for有一个动态创建的表。 The table consists of an input field in each row. 该表在每一行中都包含一个输入字段。 The number of rows inside the table is not constant (and hence the table is created dynamically). 表内的行数不是恒定的(因此表是动态创建的)。

How do I submit all the fields inside the table and route it to a controller action? 如何提交表中的所有字段并将其路由到控制器操作?

You can customize where send your data with url param in form_for helper. 您可以在form_for helper中自定义使用url参数将数据发送到的位置。

<%= form_for @article, url: {action: "create"} do |f| %>
...

Submit button will send all your rows at method "create" of ArticlesController 提交按钮将在ArticlesController的“创建”方法中发送所有行

form_for(@article, url: my_custompath_articles_path)
...

your data will be transmitted where declared by my_custompath_articles_path in 您的数据将在my_custompath_articles_path

config/routes.rb

resources :articles do
  collection do
    post my_custompath
  end
end

and

articles_controller.rb

def my_custompath
  ... your code
end

more detailed informations at ruby on rails guides ruby on rails指南上的更多详细信息

I hope this can hep you. 我希望这可以帮助您。

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

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