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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:14:55+00:00 2026-06-01T20:14:55+00:00

Settings table from schema: create_table settings, :force => true do |t| t.string name t.string

  • 0

Settings table from schema:

create_table "settings", :force => true do |t|
  t.string   "name"
  t.string   "value"
  t.datetime "created_at"
  t.datetime "updated_at"
end

Settings table has these records:

{name: "notification_email", value: "hello@monkey.com"}
{name: "support_phone", value: "1234567"}

I want the Setting.notification_email function to return “hello@monkey.com” and respectively the Setting.support_phone function to return “1234566“.

Here is what I have in my setting.rb:

class Setting < ActiveRecord::Base
  class << self
    all.each do |setting|
      define_method "#{setting.name}".to_sym do
        setting.value.to_s
      end 
    end 
  end 
end

But then when I enter Setting.notification_email in console, it gives me an error:

NameError: undefined local variable or method `all' for #<Class:0x000000053b3df0>
    from /home/adam/Volumes/derby/app/models/setting.rb:7:in `singletonclass'
    from /home/adam/Volumes/derby/app/models/setting.rb:2:in `<class:Setting>'
    from /home/adam/Volumes/derby/app/models/setting.rb:1:in `<top (required)>'
    ...
  • 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-01T20:14:56+00:00Added an answer on June 1, 2026 at 8:14 pm

    Use define_singleton_method – i.e.

    class Setting < ActiveRecord::Base
    
      self.all.each do |instance|
        define_singleton_method(instance.name) do
          instance.value.to_s
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with sets of settings for users, it has the following
I would like to create a table to store device settings. The table has
I ' am copying data from table A to table B. Table B has
Settings table contains always one row with lot of long-caption columns. Opening this in
I am trying to create a settings table view for my app. I am
im trying to save a row in my settings table, it works all fine
So it's trivial to create a Settings style table on the iPhone. The problem
Someone suggested moving a table full of settings, where each column is a setting
I have a data Table with numbers formatted according to the current regional settings.
What's the best way to structure a MySQL table for storing admin settings? Like

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.