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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:57:51+00:00 2026-06-08T11:57:51+00:00

Is there a way to automatically typecast values that are stored using ActiveRecord::Base.store? Take

  • 0

Is there a way to automatically typecast values that are stored using ActiveRecord::Base.store?

Take this totally impractical example:

class User < ActiveRecord::Base
  store :settings, accessors: [ :age ]
end

user = User.new(age: '10')
user.age # => '10'

I know I can just override the reader method for age to convert it to an integer, but I was curious if there was an undocumented way of doing it.

Trying to avoid this:

class User < ActiveRecord::Base
  store :settings, accessors: [ :age ]

  def age
    settings[:age].to_i
  end
end

user = User.new(age: '10')
user.age # => 10

Update

Looking for something like:

class User < ActiveRecord::Base
  store :settings, accessors: {:age => :to_i}
end

Or:

class User < ActiveRecord::Base
  store :settings, accessors: {:age => Integer}
end
  • 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-08T11:57:53+00:00Added an answer on June 8, 2026 at 11:57 am

    As of Rails 3.2.7 there is not a way to automatically typecast values. I’ll update this question if I ever come across a way to do it :/

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

Sidebar

Related Questions

Is there a way to automatically open up the Windows Performance Options dialog using
Is there a way to automatically clean/show unused properties in a messages.properties file, that
Is there a way to automatically set field values for models in Django when
Using Eclipse, is there a way to automatically copy a file/project's directory to a
Is there a way to automatically tell SQL Server that all tables should have
Is there any way to automatically show variables var1 and var2 and their init-values
Is there a way to automatically generate an image/figure caption using sphinx? I currently
I'm using Visio class diagram. Is there a way to automatically layout the elements
Using Visual Studio .NET 2008 or 2005, is there a way to automatically generate
Is there way to automatically maximize the output window on hitting build and then

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.