开发者

How to define and access the CONSTANTS in Rails 1.2.3?

I am confused in defining constant in Rails 1.2.3.

Here I want to define one of the url in constant and want to access at any controller. For example ::

TEMPLATE_URL = "www.google.com"

Now I want to access in any of the controller. Then I am unable to define and access thi开发者_C百科s constant.


Add following in application_controller.rb (OR application.rb)

TEMPLATE_URL = "www.google.com"

and you can access it any controller using

puts TEMPLATE_URL # www.google.com

If you want to use the same variable in your any views/helpers/models you can use it following way

ApplicationController::TEMPLATE_URL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜