Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:54:24+00:00 2026-06-02T13:54:24+00:00

Hi I have a rails app which has a table called listings. This table

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:54:25+00:00Added an answer on June 2, 2026 at 1:54 pm

    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.

    def city
      read_attribute("city") || "Not Available"
    end
    

    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:

    change_column :listings, :city, :default => "Not Available"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails app which has 2 databases. Legacy DB with table called
I have a rails app which has data in MySQL db. I am using
I have rails app which are working perfectly in the local computer. But when
So I have a Rails app (which in this case seems like it would
I have rails app which has a list of users. I have different relations
I have got a Rails app running which displays data that is generated by
I have a simple rails app with a model Task , which has 10
I'm trying to work on this Rails app which has the following objectives: /foods/
I have a rails app that has picked up a bit of traction, but
I have a sequence of migrations in a rails app which includes the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.