简体   繁体   English

在RoR中传递带有Submit_tag的参数

[英]Passing in parameters with submit_tag in RoR

In my view file I have: 在我的查看文件中,我有:

enter code here
<% @range_array.each{|dataElement| %>
        <th>
            <% i = i+1 %>
            <%= form_tag({:controller => "scores", :action => "scores"}, :method => "get")      do %>
            <%= submit_tag(dataElement, :name => i) %>
            <% end %>
        </th>
        <% } %>

In controller I try to call it: 在控制器中,我尝试称之为:

enter code here
 @range = params[:name].to_i

But when I try to use the @range variable it is always 0 regardless of which button I press, in the new url it does seem to pass the "i" value 但是,当我尝试使用@range变量时,无论我按下哪个按钮,它始终为0,在新的url中似乎确实传递了“ i”值

Use a hidden field. 使用隐藏字段。

<%= form_tag({:controller => "scores", :action => "scores"}, :method => "get")      do %>
<%= hidden_field_tag :name, :value => i %>
<%= submit_tag(dataElement) %>
<% end %>

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

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