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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:28+00:00 2026-06-17T18:23:28+00:00

I have defined a model Item which is subclass of ActiveRecord::Base It has a

  • 0

I have defined a model Item which is subclass of ActiveRecord::Base
It has a association attribute called buyer which is a member

It has a buy method to update the buyer attribute.

# do buy transaction on that item
def buy(people_who_buy, amount)
  buyer = people_who_buy
  save
  ....
end

This code cannot update the buyer attribute. The sql generate only do sql selection of member from the database.

But after I add self. before buyer , it works fine.

# do buy transaction on that item
def buy(people_who_buy, amount)
  self.buyer = people_who_buy
  save
  ....
end

It looks weird!

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

    Calling self.write_accessor is required when calling a write_accessor, while in self.read_accessor the self can be omitted (and usually is avoided to keep the code a clean as possible).


    From the community-edited ruby styleguide:

    Avoid self where not required. (It is only required when calling a
    self write accessor.)

    # bad
    def ready?
      if self.last_reviewed_at > self.last_updated_at
        self.worker.update(self.content, self.options)
        self.status = :in_progress
      end
      self.status == :verified
    end
    
    # good
    def ready?
      if last_reviewed_at > last_updated_at
        worker.update(content, options)
        self.status = :in_progress
      end
      status == :verified
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have a model called Metadatum (silly, I know) which has two fields, key
I have a base model that I extend from. In it, I have defined
I have a data model in which I have an Item that can belong
I have an entity defined as in a db First Model: public class Merlin_BR_Condiciones_Item
I have defined a User model and added a featured field to it: class
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
I have defined a function in my Navigation model that executes a query, and
Let's say i have a Model defined as: Foo {Id, Date} . Is there
So I have a self-joining model defined. Basically a post on a forum, and

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.