Skip to content

Instantly share code, notes, and snippets.

@srockstyle
Last active September 17, 2016 02:01
Show Gist options
  • Save srockstyle/8660479 to your computer and use it in GitHub Desktop.
Save srockstyle/8660479 to your computer and use it in GitHub Desktop.
Ruby on Railsで定数の指定 ref: http://qiita.com/srockstyle/items/daed31a78c343e607822
ApplicationCotnroller < ActionController::Base
NUM = 1
...
end
BookController < ApplicationController
def read
## ここに定数いれる
@number = NUM
end
end
module Constants
## Constants::NUMでアクセスできる
NUM = 1
end
## こっちはTITLEでアクセスできる
TITLE = 'Story Of The Ring'
if Rails.env == "production"
## 本番の定数
else
## 開発の定数
end
class Settings < Settingslogic
source "#{Rails.root}/config/application.yml"
namespace Rails.env
end
# config/application.yml
defaults: &defaults
artist:
band: Oasis
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
おためしあれん。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment