Hi I have a rails app which has a table called “listings”. This table has a column called “city”. But the column has no data right now, everything is null. Id like to add the string: “Not Available” to column values for all the rows in this table. How can I do that?
I tried using sql to add it directly to the DB and it wouldn’t work.
So I guess I must use the rails migration commands to achieve this. but I cannot find the exact command. I know its something like this….
rails generate migration ??
Can someone give me a hand?
Thanks
Before telling you how to actually do this with Rails, I would ask you to consider hard coding this sort of presentation logic to your database schema. You could do this at the model level, and just overwrite the accessor for this field.
Putting this information into the database can cause issues. For example, you’ll no longer be able to quickly tell which rows have a default value for
city.If you do decide you want to do this, in a migration, add: