开发者

passing parameters from submit_tag

开发者 https://www.devze.com 2023-03-08 22:50 出处:网络
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

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>&l开发者_JAVA技巧t;%= 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.


You can use button_tag with type 'submit'.

<%= button_tag 'Edit', value: skt.id, type: :submit, name: :edit %>

This will produce button with label 'Edit' and it's value skt.id

0

精彩评论

暂无评论...
验证码 换一张
取 消