I am getting a error when calling a mailer_helper method for a mailer method in a Rails 3.2.13 app -
following this post , this post put following.
in app/helpers/mailer_helper.rb:
module mailerhelper def sys_addy @sys_addy = current_site == "site1" ? "me@site1.com" : "me@site2.com" end end
attempt 1 placing helper method call above method - app/mailers/user_mailer.rb:
class usermailer < actionmailer::base helper :mailer sys_addy default :from => @sys_addy def notice_email ... end end
attempt 2 placing helper method call inside method - app/mailers/user_mailer.rb:
class usermailer < actionmailer::base helper :mailer def notice_email sys_addy ... mail( ...:from => @sys_addy ) end end
in both cases got:
nameerror (undefined local variable or method `sys_addy'
thanks help.
i think can use following:
class usermailer < actionmailer::base include mailerhelper helper :mailer
but problem solution helper can't know result of current_site
(i guess stocked in user's session?).
a workaround use thread.current
in order store data dynamically (can updated):
thread.current[:site] = site
this solution not safe, make sure secure access variable , never put user's input in thread.current
.
Comments
Post a Comment