简体   繁体   English

Rails视图并向“新”方法提交发布请求

[英]Rails views and submitting a post request to the “new” method

I have a rails view with automatically generated content that is pulled from an API. 我有一个Rails视图,其中包含从API提取的自动生成的内容。 Essentially, from the index, I want the user to have the ability to submit a form that will do an action on that data. 本质上,我希望用户能够从索引中提交将对该数据执行操作的表单。 Thus I need to submit the form, and any information I need to pass on in that form. 因此,我需要提交表单以及需要在该表单中传递的所有信息。

The rails view data is populated using the following code: 使用以下代码填充rails视图数据:

<form>    
<table class="dataTable">
 <tr>
  <th><%= button_to "Add To-Do Lists", new_setting_path, :class => 'button regular', :method => "get", :style=>'float: left; position: relative; margin-bottom: 0px;' %><%= link_to "customize", new_setting_path, :method => "get", :style=>'float: left; position: relative; top: 5px;' %>
 </th>
<th><strong>Project Name</strong></th>
<th></th>
  <th></th>
  </tr>

  <% @todo_list_masters.each do |todo_list_master| %>
  <tr>
    <td><input type="checkbox" id="<%= todo_list_master.id %>" value="Car"></td>
    <td><%= todo_list_master.name %></td>
    <td><a href="<%= raw todo_list_master.url %>">Open In Basecamp</a></td>
    <td><%= link_to "Set as Master", {:controller => :settings, :action => :basecamp_todolist_master, :basecamp_model_id => todo_list_master.id, :basecamp_model_name => todo_list_master.name } %></td>
  </tr>
  <% end %>
</table>
</form>

So my goal, is to submit which checkbox's are checked and pass that to the new method in my controller. 所以我的目标是提交选中的复选框,并将其传递给控制器​​中的新方法。 Obviously, I've wrapped that whole thing in the "form" tag, and so that's pretty much all I need. 显然,我已将整个内容包装在“ form”标签中,因此这几乎是我所需要的。 Any ideas about the best way to do this? 关于最佳方法的任何想法? Ajax or something maybe? 阿贾克斯还是什么?

Also, as a quick side note, these elements don't actually reflect anything in the database, it's just JSON data I send. 另外,作为一个简短的说明,这些元素实际上并不反映数据库中的任何内容,而只是我发送的JSON数据。

I've previously answered a similar question to this at the following link. 我以前在以下链接中回答了与此类似的问题。

HTTP Requests with Selection Checkboxes in Ruby on Rails Ruby on Rails中带有选择复选框的HTTP请求

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

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