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

  • Home
  • SEARCH
  • 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 8600399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:36:30+00:00 2026-06-12T01:36:30+00:00

I have an attribute in my model that is stored as text but interpreted

  • 0

I have an attribute in my model that is stored as text but interpreted as a rational. I have this method to handle that:

def start
  read_attribute(:start).to_r
end

When I set the start attribute to a new value, the start_was helper method returns a string, instead of a rational, but before I do so, it returns the correct value. Why?

Loading development environment (Rails 3.2.8)
1.9.3p194 :001 > d = Day.find(55)
  Day Load (8.7ms)  SELECT "days".* FROM "days" WHERE "days"."id" = ? LIMIT 1  [["id", 55]]
 => #<Day id: 55, date: "2012-03-30", start: "1/2", finish: "2/2", created_at: "2012-09-18 15:16:42", updated_at: "2012-09-19 08:20:41", day_year_id: 1> 

1.9.3p194 :002 > d.start_was
 => (1/2) 

1.9.3p194 :003 > d.start=0
 => 0 

1.9.3p194 :004 > d.start_was
 => "1/2" 
  • 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-12T01:36:32+00:00Added an answer on June 12, 2026 at 1:36 am

    I think the reason is this method in ActiveModel (activemodel-3.2.8\lib\active_model\dirty.rb)

    # Handle <tt>*_was</tt> for +method_missing+.
    def attribute_was(attr)
      attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
    end
    

    As you see, if attribute was not actually changed it just calls its own getter, in your case hitting your start method which does the transformation. But if the attribute is actually changed, it reads its raw value from the changed_attributes storage.

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

Sidebar

Related Questions

[Updated a bit] I have a Task model that has a :completed boolean attribute.
I've been wondering, suppose I have a model with an attribute that in every
I have notes attribute in Product model with text something, something else. In views
I have this attribute in my view model: [CustomRequired, EmailRegex] [Display(Name = KeepInformedPersonMail, ResourceType
Let's say, I have a backbone.js model named Item that is stored in an
I have a Rails model class with a serialized Hash attribute, like this: class
I have a controller for an API that looks like this: def index respond_to
Assume that I have a backbone model that has a bunch of boolean attributes:
I have authentication logic that uses cookies. The model attributes are initialized from cookies,
I have a model, ModelRun , that accepts nested attributes for another model, ParameterValue

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.