<% 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
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
Spanish
Persian
Is this correct?Then how can I access this in controller and to know
which one is clicked and which one not?
<% 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.