rails g migration add_anonymous_to_message anonymous:???
If I were adding a title etc to a message then I would put rails g migration add_title_to_message title:string but if :anonymous is a check box in the message submit form how do I add it to the database so that there are only two options: box checked=anonymous and box unchecked=username displayed?
Thanks
Are you sure you need another database column? What you could do is
username:stringwhich allowsNULLvalues (default)anonymousis unchecked, saving a blank username is invalidanonymousis checked, the username is always saved as blank (nil), regardless of the form valuemessage.username.nil?If for some reason you do need a separate DB column for
anonymous, it should look like this:rails g migration add_anonymous_to_message anonymous:booleanAlthough not all RDBMS support
booleancolumns (MySQL doesn’t), Rails takes care of this by generating aTINYINT(1)or similar column when you specifyboolean, which is set to either0or1.