Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing parameters from submit_tag

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%>
like image 716
user558138 Avatar asked May 27 '11 09:05

user558138


1 Answers

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.

like image 123
Matteo Alessani Avatar answered Oct 20 '22 11:10

Matteo Alessani