Rails 3 / Setting Custom Environment Variables

后端 未结 4 1331
北荒
北荒 2020-12-13 10:54

I am trying to create a rails application that assigns one value to a variable when the environment is the development environment, and another value to that same variable w

4条回答
  •  旧巷少年郎
    2020-12-13 11:43

    You can find out the environment like this:

    ruby-1.9.2-p0 > Rails.env
      => "development"
    

    Store the value in a global variable in your config/application.rb for example:

    $foo = "something"
    

    You could also assign the variable in your config/environments/ files instead of deciding based ond Rails.env in application.rb. Depends on your situation.

提交回复
热议问题