rails 3, checkbox from table database
how to create a list of checkboxes from a table of the database in my case I have a table Employees who need a type of employee assigned example:
select * from type_employeed
generate:
<input type='checkbox' value='1'> Vendedor
&l开发者_Python百科t;input type='checkbox' value='2'> Proveedor
<input type='checkbox' value='3'> Jefe de zona
<input type='checkbox' value='4'> Manejador
Your question is not very clear. But in general, this is the way to go, to use check boxes.
Suppose, you have a field in your model Post, say :allow_comment
. So, in your modal form, it would look like this
<%= f.check_box :allow_comment %>
If you want a default value for your checkbox, you should set the value of that field to 0 or 1 in your controller. So, in the new action of your controller PostsController, you would write,
@post.allow_comment = 1 # will set the default value of check box at 1
To learn more on check boxes, watch Ryan Bates' Screencast
精彩评论