gemfile 中加入:
# setting
gem 'settingslogic'
新建一个app/model/settings.rb文件,在文件中加入
class Settings < Settingslogic
source "#{Rails.root}/config/application.yml"
namespace Rails.env
end
新建一个config/application.yml文件,在文件中加入
defaults: &defaults
hash1:
hash2: nested settings
hash3: 20
hash4: 这个是默认的方法,Setting.hash4进行读取
development:
<<: *defaults
hash5: 在开发者模式,Setting.hash5,就会显示
test:
<<: *defaults
production:
<<: *defaults
在控制台中使用:
>> Rails.env
=> "development"
>> Settings. hash1
=> "#<Settingslogic::Settings ... >"
>> Settings. hash1. hash2
=> "nested settings"
>> Settings. hash3
=> 20
>> Settings. hash4
=> " 这个是默认的方法,Setting.hash4进行读取"
>> Settings. hash5
=> "在开发者模式,Setting.hash5,就会显示"
修改setting的值:
Settings[:hash5] = "这里不能用Settings.hash5,要用Settings[:hash5] ,不然会报错"
更多设置
网友评论