-
-
Save hannesfostie/f50b7022b4e1bee46e74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GlobalSetting | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include Mongoid::ForceBoolean | |
field :test, type: String, default: "foo bar" | |
def self.value(attribute) | |
global_setting = first || create! | |
global_setting.public_send(attribute) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[maloik] ~/dev/project % bin/rails c | |
Loading development environment (Rails 4.2.3) | |
irb(main):001:0> @text = GlobalSetting.value(:test) | |
=> "foo bar" | |
irb(main):002:0> @text.gsub! /bar/, 'foo' | |
=> "foo foo" | |
irb(main):003:0> @text | |
=> "foo foo" | |
irb(main):004:0> GlobalSetting.value(:test) | |
=> "foo foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment