Ruby on Rails Friday, January 29, 2016

> On Jan 25, 2016, at 9:22 PM, jai kumar <jaiksah@gmail.com> wrote:
>
> <% @fixture.each do |data| %>
> <% num = 1 %>
> <td> <%= data.matchdate %></td>
> <td><%= radio_button_tag(num,data.team ,:checked =>true) %><%= label :team, data.team %> </td>
> <td> <%= radio_button_tag(num,data.winteam) %><%= label :team, data.winteam %></td>
> <% num = num + 1 %>
>
> </tr>
> <% end %>
>
>
> how to work on params of radio button in case of multiple rows? for one row i can do it using params[num].
>

First off, I am reasonably sure that giving a form field a numerical name is going to fail, although I am not 100% sure that Rails doesn't do something clever about that. I know that in HTML, the ID attribute may never start with a number, not sure about the name attribute, though.

Second, if you want all of these choices to arrive at the server in a meaningful chunk, your best bet is to name them so that the browser will treat the value assignments like a nested hash, rather than a bunch of dissociated individual values. Take a look at this form submission in your console while it's running in development. What do you see in the params hash that prints out as the form is submitted?

Do your teams have a corresponding ID? Why not use that as your key, rather than the manually-incremented num?

Walter


> please suggest.
>
> thanks
> Jai
>
> --
> 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/5e2f92db-9c77-4151-825a-fb3d062e8a62%40googlegroups.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/A54A8AFB-0A21-40F9-8610-B105705975C2%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment