In Coverlist, I have a model (scaffold?) called Users, which has a small number of components: name, email, password, all created when a user makes an account.
But, in order to expand the feature set of the site, I’d like for users to be able to add a short bio, a website, their Twitter handle and their full name (since name actually refers to username, and their vanity url, ie: coverlist.com/users/Dani).
The way we do this is with a migration:
rails g migration AddDetailsToUsers fullname:string twitter_handle:string bio:text website:string
A “string” refers to shorter text such as a username or email, while “text” is for longer text, like a summary, or in this case, a bio.
I ran that, and then I added <%= f.input :bio %> to the “edit user” view to test it out – and got an error. Do I need to run rake db:migrate?
Then I added a bio, and got another error: Can’t mass-assign attributes.
I needed to go to my user model and add bio to the attr_accessible line where the other attributes are listed. The same will go for all the attributes i just added.
One last thing – a bio is no good unless other people can see it!
I went to the user show view and added the @user.bio in a <p> tag right under the user name. I will have to jump into the CSS later to make it look nice, but just wanted to prove I could put it there.
So, that was fun!