从 submit_tag 传递参数 [英] passing parameters from submit_tag

查看:35
本文介绍了从 submit_tag 传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表,每个表都带有编辑按钮.如何检测点击了哪个编辑"按钮?

<tr><th>SkillSet ID</th><th>技能组名称</th><th></th></tr><% for skt in @skillset %><tr><td><%=skt.SkillSetID%</td><td><%= skt.SkillSetName%></td><td><%= submit_tag "编辑"-%></td></tr><%结束%></font></table><br></td>

<%end%>

解决方案

您可以使用 submit_tag 方法的 name 选项:

<%= submit_tag "编辑", :name =>编辑[#{skt.id}]"%>

然后在您的控制器中,您可以检查 params["edit"] 中的密钥,您应该在其中找到类似 (skt.id) => 的内容.''

或者,您可以添加一个 hidden_​​field 来跟踪您正在编辑的 skt 的 ID.

I have the following table with edit button in each. How can I detect which Edit button was clicked?

<table width="50%" border="1" height="50%" style='position:relative'><font color = "black">
    <tr>

    <th>SkillSet ID</th>
    <th>SkillSet Name</th>
    <th></th>
    </tr>

    <% for skt in @skillset %>
    <tr>

        <td><%= skt.SkillSetID%></td>
        <td><%= skt.SkillSetName%></td>

        <td><%= submit_tag "Edit"-%></td>
    </tr>
    <% end %>
    </font></table>
    <br>

    </td>
    </div>
    <%end%>

解决方案

You can use the name option of the submit_tag method:

<%= submit_tag "Edit", :name => "edit[#{skt.id}]" %>

Then in your controller you can check the key inside params["edit"], where you should find something like (skt.id) => ''

Alternatively, you could add a hidden_field to track the id of the skt you're editing.

这篇关于从 submit_tag 传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆