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 7278337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:51:39+00:00 2026-05-28T22:51:39+00:00

developers! I can’t understand next situation For Example I have model class Pg::City <

  • 0

developers! I can’t understand next situation

For Example I have model

class Pg::City < ActiveRecord::Base
   belongs_to :country  
   #virtual accessors
   attr_accessor :population
   #attr_accessible :city, :isdisabled,  :country_id

end

I can use code like this:

c = Pg::City.new({:population=>1000})
puts c.population
1000

But if I uncomment attr_accessible code above throw warning

WARNING: Can't mass-assign protected attributes: population

How can I use virtual attributes for mass-assigmnment together with model attributes?
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-05-28T22:51:40+00:00Added an answer on May 28, 2026 at 10:51 pm

    Using attr_accessor to add a variable does not automatically add it to attr_accessible. If you are going to use attr_accessible, then you will need to add :population to the list:

    attr_accessor :population
    attr_accessible :city, :isdisabled, :country_id, :population
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For reasons that only the developers can understand, Firefox will create and open .url
I have a repositories, i want to have two views: Developers can see the
I'm starting a .NET project and my developers have their own laptops. How can
How can two developers work on a same C++ code base such that they
Does Mail.app (Mac) have an API where developers can create plugins for Mail? I'm
I'd like to have a setup where developers can resolve/retrieve dependencies from a URL
Can someone guide me on the best practice for this situation; I have a
I am told that good developers can spot/utilize the difference between Null and False
Is it possible? Developers can use SMS URLs to populate the phone number, but
I'm building a jar so that other developers can use the view I create

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.