Added New Column into database but couldn't retrieve the data..

Hi base rails, I'm currently exploring further into rails databases and I'm just learning into adding new fields / destroying new fields... I know that this function will be used frequently as the site is not fully confirmed yet.. Anyways heres my question.. 1. I want to add new fields into my current database... I know the answer is rails generate migration AddSomethingtoDatabasename fieldname:integer it works but after adding I couldn't retrieve my data... What am I doing wrong? Any ruby experts out there please help me...

Posted over 4 years ago by Christopher Leong
Posted over 4 years ago by Alex Yang

Let's say you've added a 'price' field to your User database by running 'rails generate migration AddPriceToUsers price:integer'. You'd then need to run 'rake db:migrate' to make the change to your database, and then restart your Rails server if necessary.

Then to access the data, you can now use '.price' on any User object. So for example, if you've already defined the variable '@user', then you would just use '@user.price'. Hope this makes sense and happy holidays!

1