美文网首页
Gem settingslogic 使用

Gem settingslogic 使用

作者: 程序萌 | 来源:发表于2018-04-27 10:39 被阅读0次

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] ,不然会报错"

更多设置

相关文章

网友评论

      本文标题:Gem settingslogic 使用

      本文链接:https://www.haomeiwen.com/subject/dpxblftx.html