Adding Custom Constants - UW-Libraries/druw GitHub Wiki
Although the Hydra folks do plan on adding more constants into the system, the current set available in
config/locales/sufia.en.yml
is very sparse. Fortunately, it is very simple to add new constants.
Following the pattern shown in config/locales/sufia.en.yml
, add your constant along with its unique name.
So that you can refer to the constant in views, you need to create a helper function like the ones defined
in /home/vagrant/.bundle/ruby/2.3.0/sufia-*/helpers/sufia/sufia_helper_behavior.rb
These functions take the basic form of:
def constant_name_helper
t('sufia.constant_name')
end
where constant_name is the name of the constant you defined in config/locales/sufia.en.yml
.
These new helper functions should be added to or imported into the module in
app/helpers/sufia_helper.rb
.
Finally, you need to refer to the constant in a view file. All this requires is including this rails snippet in your view code:
<%= constant_name %>
where constant_name_helper is the name of the helper function you defined earlier.