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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:17:51+00:00 2026-05-17T18:17:51+00:00

I am confused about how to access the attributes of an ActiveRecord instance from

  • 0

I am confused about how to access the attributes of an ActiveRecord instance from a method within the ActiveRecord instance.

For example I have a Lead class that inherits from ActiveRecord:

class Lead < ActiveRecord::Base
end

I have the following scaled down migration file that shows the columns of an ActiveRecord table:

class CreateLeads < ActiveRecord::Migration
  def self.up
    create_table :leads do |t|
      t.string :phone_1
      t.string :phone_2
      t.string :web
      t.string :fax
      t.timestamps
    end
  end
  def self.down
    drop_table :leads
  end
end

I am using send in a method of the Lead class to set these attributes internally like this:

def instance_method(prop)
  self.send("#{prop}=".to_sym, value_node.text) 
end

The question I have is how do I access these :phone_1, :phone_2 attributes when within the ActiveRecord instance itself without having to use send which is the only way I can think of. I think these attributes are accessed via method_missing when accessing them from the public interface like this:

puts lead.phone_1

But I have no idea how to access them from within the ActiveRecord instance apart from via send.

Is it possible?

  • 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-17T18:17:52+00:00Added an answer on May 17, 2026 at 6:17 pm

    You can reference AR attributes directly from within any AR instance. No need for any ‘send’ magic:

    def some_method
     self.some_attribute='value' # with or without self
     x = some_attribute
    end
    

    What lead you to believe otherwise?

    If you need to bypass AR’s built in accessors you can use read_attribute and write_attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question that I am a little bit confused about. I am
I am confused about the different possibilities to express a 3-Tier architecture. Data-Access-Layer Business-Layer
I'm confused about this bit of code from the HTTP package : type HandlerFunc
I'm a little confused about the python in operator for sets. If I have
I'm a little confused about how the standard library will behave now that Python
I have a question about handling my models. I get all confused. When I
I'm a little confused about how to use the cursor to access the data
I'm confused about how Archiva fully works. I understand that if we had a
I am a bit confused about the facebook graph api and access tokens. I
I am confused about Cyclic dependencies. I have two .m file and I need

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.