Eugene
Eugene

Reputation: 689

Checkbox in form

Sorry for stupid question but I dont understand how to use check_box helper in rails. I read the documentation, but did not understand how create ckeckbox in form for user[:role] with params customer and provider(and maybe admin)

Upvotes: 0

Views: 88

Answers (3)

user1291365
user1291365

Reputation: 576

There is an example. It should works for scaffolded User model with :role atribute.

<% for role in %w(customer provider admin) %>
  <p>
    <%= check_box_tag "role", role, (params[:role] && params[:role].include?(role)) %>
    <%=h role %>
  </p>
<% end %>

Upvotes: 1

korada
korada

Reputation: 586

first read and understand the brief Ganesh pointed out. If user can have only one role, you need radio buttons or select list. For multiple roles, you need a Role model and check boxes.

Upvotes: 1

Ganesh Kunwar
Ganesh Kunwar

Reputation: 2653

The brief of check_box helper see: check_box_tag

Upvotes: 1

Related Questions