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