Best way to handle view and helper-only constants in Rails Best way to handle view and helper-only constants in Rails ruby-on-rails ruby-on-rails

Best way to handle view and helper-only constants in Rails


You can define constants in helpers, but you will need to refer to them by their fully qualified name in your views.

application_helper.rb

module ApplicationHelper  MyConstant = "something"end

In any view:

<%= ApplicationHelper::MyConstant %>


Put it in config/initializers/constants.rb and it will be availble everywhere.