Reputation: 11980
I have User
model and there are boolean attributes admin
, employee
, student
inside User
model , how to make one of those attribute true if selected using a list box
Upvotes: 0
Views: 419
Reputation: 21815
<%= form_for :user do |f| %>
<%= f.checkbox :admin %> Admin
...
This will create a form and a checkbox with name user[admin]
and so on.
If you want checkboxes to be selected according the value in User instance remember to pass @user
, where @user = User.find(some_id)
In your controller you will have:
def create # or def update
@user = User.new params[:user] # or User.find
if @user.save # or @user.update_attributes
# handle success
else
# handle error
end
end
Upvotes: 1