Ruby on Rails Monday, May 26, 2014

On May 26, 2014, at 10:00 AM, Fab Forestier wrote:

> Walter Davis wrote in post #1147109:
>> On May 26, 2014, at 4:28 AM, Fab Forestier wrote:
>>
>>>> htttp://localhost:3000/operations/some_action?value=73. You can
>>>> easily do this with something like link_to("label",
>>>> :controller="operations", :action="some_action", :value=73). Then in
>>>> the action in the operations controller the variable params[:value]
>>>> will have the value 73.
>>>>
>>> Yes but my question was how can I have the value equal to the number of
>>> the line of the table where the button is?
>>
>> If you are dynamically generating the table, then you know what index
>> each row of that table is, don't you? And if you are generating the
>> table using a collection of data, then you know the :id (for example, or
>> the color or stock number or any of the parameters of the underlying
>> object) of each item as you draw the table. Adding that value to the
>> link_to generated code is a trivial exercise.
>>
>> for foo in @foos
>> <tr>
>> <td>foo.bar</td>
>> <td>foo.baz</td>
>> <td>link_to foo.boo, foo.blarg, :stock_number => foo.id</td>
>> </tr>
>> end
>>
>> Does that help? (Left off all the erb stuff 'cause it's early.)
>>
>> Walter
>
> I'm sorry walter but I don't really understand what you said, but the
> code to display my table is :
>
> <% @defautrec.each do |n| %> <!--Loop to display-->
> <tr>
> <td><%= n.nomdefaut.nom_defaut%></td>
> <td><%= n.repere%></td>
> <td><%= link_to controller: "pages", action: "ajouter" do%><button,
> class="btn btn-mini btn-success">Ajouter</button><%end%></td>
> </tr>
>
> But the in the methode ajouter how can I have something like
> @myvariable=n or @myvariable=@defautrec[i] where I is the current line
> of the table?
>

Like this:

<% @defautrec.each_with_index do |n, idx| %> <!--Loop to display-->
...
<td><%= link_to( controller: "pages", action: "ajouter", myvariable: idx) do%><button,

...

Walter


> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2a0b12eb5a4af2ba52535cfb429419bc%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4C4F7C56-97B5-4C66-B91C-C8EF676F54D9%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment