Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:25:21+00:00 2026-06-17T15:25:21+00:00

I have this task with delayed_job: def any_method UserMailer.delay(queue: Email, priority: 3).to_user_when_his_account_is_suspended(user, locale) end

  • 0

I have this task with delayed_job:

def any_method
 UserMailer.delay(queue: "Email", priority: 3).to_user_when_his_account_is_suspended(user, locale)
end

If I send a email as rails mode:

def any_method
 locale = params[:locale]
 UserMailer.to_user_when_his_account_is_suspended(order, locale).deliver
 #more code
end

The email is sent on the proper locale/language.

However delayed_job does not recognize the proper locale/language. On this case I get locale with locale = params[:locale], you can see the next example:

locale = params[:locale]
UserMailer.delay(queue: "Email", priority: 3).to_user_when_his_account_is_suspended(user, locale)

Mailer Code:

 def to_user_when_his_account_is_suspended(user, locale)
  @user = user
  @locale = locale
  mail(:to => @user.email, :subject => t('.user_account_has_been_suspended'))
 end

How can I fix this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:25:22+00:00Added an answer on June 17, 2026 at 3:25 pm

    Okay, first, why I think your ‘existing’ mailer code is working when it’s not in DJ.

    Your locale is set through I18n.locale. This is set on a thread specific level…hence, assuming you are setting I18n.locale somewhere for the user, then Rails is using that to send.

    However, DJ will use a separate process entirely…so it can’t inherit the locale! This means it will fall back to whatever your default locale is.

    How I’d change your mailer:

    def to_user_when_his_account_is_suspended(user, locale)
      @user = user
      old_locale = I18n.locale
      I18n.locale = locale
      mail(:to => @user.email, :subject => t('.user_account_has_been_suspended'))
      I18n.locale = old_locale
    end
    

    This will temporarily change the language for the thread in the mailer, and then, like a good citizen, it will set it back to the old value at the end of the request.

    Obviously, if you are doing this all over the place, you want to extract it into a helper method that yields control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have this task for the project with 4 nested subprojects using Maven: For
I have this Maven task to generate Java classes from an XSD file using
I have this little rake task: namespace :db do namespace :test do task :reset
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
I have a task in Python and i run this task for first time
I have had no luck with this task so far so grateful for any
I would like to have this behavior in a task history stack: First task
I have some basic idea on how to do this task, but I'm not
I have always wondered what's the best way to achieve this task. In most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.