Forum: Ruby on Rails Create CheckBox

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
57f355c4d8bab93d67dfbd1691ab0be4?d=identicon&s=25 Devi Rv (devirv)
on 2009-04-18 09:19
Hai,

I want to create a checkbox the values are table field values. In my
controller
  @emptypes = Emptypes.find(:all)
In View
  <% @emptypes.each do |c| %>
  #Write checkbox generating code here
    <%= check_box("contacts",emptypes.types)%>
  <%end%>
 Anyknows please suggest me how to create a checkbox (values are
retrived from table).

-with Thanking&Regards
devi.r
57c6a3276ed9cbb3b271e5dd067f0724?d=identicon&s=25 Indu R Nair (indu)
on 2009-04-18 09:41
Devi Rv wrote:
> Hai,
>
> I want to create a checkbox the values are table field values. In my
> controller
>   @emptypes = Emptypes.find(:all)
> In View
>   <% @emptypes.each do |c| %>
>   #Write checkbox generating code here
>     <%= check_box("contacts",emptypes.types)%>
>   <%end%>
>  Anyknows please suggest me how to create a checkbox (values are
> retrived from table).
>
> -with Thanking&Regards
> devi.r

<% @emptypes = Emptypes.find(:all)%>
     <% @emptypes.each do |c| %>
    <%= check_box "contacts","xxxxx",{},emptypes.types %>
in the place of "xxxxx" you have to mention the method name
57f355c4d8bab93d67dfbd1691ab0be4?d=identicon&s=25 Devi Rv (devirv)
on 2009-04-20 06:32
Hai,

      The check box is created but there is no label for this. How to
print with label. Please suggest me.What we write the
method(valuesmethod())? In my code is

<% @emptypes.each do |emptypes| %>

    <%= check_box "contacts","valuesmethod",{},emptypes.types %>

<% end %>

Regards
devirv
57f355c4d8bab93d67dfbd1691ab0be4?d=identicon&s=25 Devi Rv (devirv)
on 2009-04-20 07:22
Hi,

  I wrote the folling code segment it's display the labels.
  <% for emptypes in @emptypes %>
  <%= check_box("types", emptypes.id, (@emptypes.include?(emptypes) ?
{:checked => false} : {:checked => false} )) %> <%= emptypes.types %>
<% end %>

Thank You for all to given suggestion.

Regards
devirv
This topic is locked and can not be replied to.