Jon Hewer
2006-Jul-18 16:26 UTC
[Rails] updating boolean field in model from check box value
hello i am having a bit of trouble with updating the values of a boolean field in my database/model given the value returned by a check box i am generating the check box as follows: check_box("user", "enabled") which produces <input checked="checked" id="user_enabled" name="user[enabled]" type="checkbox" value="1" /><input name="user[enabled]" type="hidden" value="0" /> no problems there - it is reading the value out of the model/database and checking the box correctly n.b. the database stores a 1 for true and 0 for false however, if i uncheck the checkbox, for example, and update using this method in my controller: def update @user = User.find(params[:id]) if @user.update_attributes(params[:user]) #success else #failed end end it doesn''t seem to commit the change i have tried using the alternative check_box method specifying the checked and unchecked values as "true" and "false" but this doesn''t work either. any ideas? thanks -- Posted via http://www.ruby-forum.com/.