ruby on rails - How do I get a constant recongized in my mailer file? -
with rails 5, how constant recognized in mailer file? have file, app/mailers/user_notifier.rb,
class usernotifier < actionmailer::base ... # send notification email user price def send_confirmation_email(user_id) @user = user.find(user_id) mail( :to => @user.email, :subject => constants::email_confirmation_subject ) end end
but when gets line, ":subject => constants::email_confirmation_subject )" dies error
uninitialized constant constants::email_confirmation_subject
despite fact have constant defined in config/initializers/global.rb file
module constants # subject email confirmations email_confirmation_subject = "please confirm email." end
how fix this?
you don't need prefix constant module name. constant available in global scope.
email:
def send_confirmation_email(user_id) @user = user.find(user_id) mail( :to => @user.email, :subject => email_confirmation_subject ) end
config/initializers/global.rb
email_confirmation_subject = "please confirm email."
although, i've got suggest use internationalization in rails since it's built purpose http://guides.rubyonrails.org/i18n.html
Comments
Post a Comment