Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with :locale in ApplicationController and SubscriptionsMailer #178

Open
dannatobigodo opened this issue Sep 4, 2020 · 0 comments

Comments

@dannatobigodo
Copy link

In a project we use a scope in routes for language switching, which includes the commontator mount:

scope path: '(:locale)', constraints: { locale: /#{I18n.available_locales.join("|")}/ } do
  mount Commontator::Engine => '/commontator'
  # ...
end

We had to customize ApplicationController and SubscriptionMailer due to routing errors in using url helpers:

class Commontator::ApplicationController < ActionController::Base
  before_action :set_locale

  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end

  def url_options(options = {})
    options.merge(locale: I18n.locale, only_path: true)
  end
  # ...
end
class Commontator::SubscriptionsMailer < ActionMailer::Base
  def url_options
    { locale: I18n.locale }.merge(super)
  end
  # ...
end

In particular, Commontator failed to send notifications of new comments, because the :locale parameter was filled with the commontable object, resulting in the error: "No route matches ... missing required keys: [: id]".
Also, after creating a comment, the current :locale was not passed and translations in the default language appeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant