Insanity
Insanity

Reputation: 25

Grails pass parameter from loop to controller

In Grails I'm trying to delete a record from a (HTML) table, I want to achieve this by passing the ID of the object to the controller. So there is a table in HTML and the user clicks "delete" and the item is deleted from the database. (This logic works according to the unit tests, the problem is passing the ID from view -> controller) I have tried several solutions found on here such as

<g:each in="${recipe}" var="item">
<tr>
   <td>
      ${item.recipeName}
   </td>
   <td>
      ${item.people}
   </td>
   <td>
      <g:link controller="UserRecipe" action="delete" params="[id: '${item.id}']" class="class">Info to Display</g:link></tr>
</g:each>

Which doesn't crash but calls the controller correctly, though the value of the id = null. When I manually edit the url and add /4 for example, the ID will be four. Several solutions on here showed how to pass parameters, but the error arrises when I try to pass a parameter which I access using the ${} notation with these solutions, e.g. using createLink and a params list, it will crash the application because it's a nested ${${}} it seems.

Upvotes: 0

Views: 502

Answers (1)

tim_yates
tim_yates

Reputation: 171054

You need to change your params to:

params="[id: item.id]" 

Upvotes: 1

Related Questions