Hi I have <% for language in @languages %> <%= language.language %> <%check_box("user","language_id",{},checked_value = "1", unchecked_value "0") %> <% end %> What I am trying to do is if a user check more than one language say English and Spanish I shud get bothe these values to controller and there I can craete the user and save the languages there.Please tell me how can I do this I tried like above but always getting params[:user][:language_id] as 0 TABLES Languages table contains id, language Users table contains id, name, language_id MODEL Relation ships mentioned class Language < ActiveRecord::Base has_many :users end class User < ActiveRecord::Base belongs_to :language end Thanks in advance Sijo -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 17, 6:44 am, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > I have > > <% for language in @languages %> > <%= language.language %> <%> check_box("user","language_id",{},checked_value = "1", unchecked_value > "0") %> > <% end %>You''ve got to use check_box_tag and not check_box, set the parameter name to user[language_id][] and give each checkbox a different value (ie the id of the corresponding language. Fred> > What I am trying to do is if a user check more than one language > say English and Spanish I shud get bothe these values to controller > and there I can craete the user and save the languages there.Please tell > me how can I do this I tried like above but always getting > params[:user][:language_id] as 0 > > TABLES > Languages table contains id, language > Users table contains id, name, language_id > MODEL > Relation ships mentioned > class Language < ActiveRecord::Base > has_many :users > end > > class User < ActiveRecord::Base > belongs_to :language > end > > Thanks in advance > Sijo > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Thanks for the reply I tried like <% for language in @languages %> <%= language.language %> <%= check_box_tag("user[#{language.id}][]","#{language.id}") %> <% end %> And the source obtained is English <input id="user[1][]" name="user[1][]" type="checkbox" value="1" /> Spanish <input id="user[2][]" name="user[2][]" type="checkbox" value="2" /> Persian <input id="user[3][]" name="user[3][]" type="checkbox" value="3" /> Is this correct?Then how can I access this in controller and to know which one is clicked and which one not? Sijo -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 17 Sep 2008, at 10:41, Sijo Kg wrote:> > Hi > Thanks for the reply I tried like > <% for language in @languages %> > <%= language.language %> <%> check_box_tag("user[#{language.id}][]","#{language.id}") %> > <% end %> > And the source obtained is > English <input id="user[1][]" name="user[1][]" type="checkbox" > value="1" > /> > Spanish <input id="user[2][]" name="user[2][]" type="checkbox" > value="2" > /> > Persian <input id="user[3][]" name="user[3][]" type="checkbox" > value="3" > />> > Is this correct?Then how can I access this in controller and to > know > which one is clicked and which one not? >no - you want the output to be <input id="user[language_id][]" name="user[language_id][]" type="checkbox" value="3" /> and then params[:user][:language_id] will be an array Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is there a way to have this working while being able to use labels, and being valid HTML? Ie, unique IDs for the inputs?> no - you want the output to be > > <input id="user[language_id][]" name="user[language_id][]" > type="checkbox" value="3" /> > > and then params[:user][:language_id] will be an array > > Fred-- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---