开发者

Create a global variables file and access it everywhere in Rails app; models, controllers and delayed jobs

开发者 https://www.devze.com 2023-03-31 05:30 出处:网络
I have some 40 variables defined like:-- add_notice_sender = \"You added %s to the %s group.\" add_notice_everyone = \"%s added %s to the %s group.\"

I have some 40 variables defined like:--

 add_notice_sender = "You added %s to the %s group." 
 add_notice_everyone = "%s added %s to the %s group."
 accept_everyone = "%s has joined the %s group."

I will be replacing %s with values in various places may be in controller or model or delayed 开发者_开发技巧job. How can I create a single file for these kind of variables and use it from there only. I don't want to place it here and there in whole application.

  • I tried in initializers directory but delayed job is not accessing it.
  • I tried placing it in a file under lib directory. still no luck.


From Benoit Garret's comment:-

config/locales/en.yml and the I18n is the right place to have these kind of variable declarations.

0

精彩评论

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