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

I18n does not seem to work with I18n Active Record #236

Open
andreas-it-dev opened this issue Feb 23, 2023 · 1 comment
Open

I18n does not seem to work with I18n Active Record #236

andreas-it-dev opened this issue Feb 23, 2023 · 1 comment
Labels
investigate Something is probably wrong question Further information is requested

Comments

@andreas-it-dev
Copy link

Tell us about your environment

Ruby Version: 3.1.3

Framework Version (Rails, whatever): 7.0.4.2

Action Policy Version: latest

Reproduction Script: n/a

What did you do?

i am using I18n active record but this doesnt seem to fly with the I18n support built into action_policy.

What did you expect to happen?

it should use a translation key thats actually stored in the db: action_policy.policy.session.create?

What actually happened?

it used the default key: action_policy.unauthorized

my application_controller looks like this:

  rescue_from ActionPolicy::Unauthorized do |e|
    message = {
      message: e.result.message,
      show: true,
      type: 'error' }
    render json: { message: message },
           status: :forbidden
  end

i have a SessionPolicy

class SessionPolicy < ApplicationPolicy
  authorize :user

  def create?
    false
  end

  def destroy?
    true
  end
end

which is called by this in my SessionsController:

  def create
    message = {
      message: I18n.t('session.create.unsuccessful'),
      show: true,
      type: 'error' }
    user = User.authenticate(session_params[:email], session_params[:password])
    authorize! user, with: SessionPolicy, context: { user: user }

 <snip>
  end

maybe i do something wrong?

@palkan
Copy link
Owner

palkan commented Mar 14, 2023

We have no assumptions on I18n backend, we simply call I18n.t:

Can you please provide the value of the e.result.all_details? Also, e.result.rule and e.result.policy.identifier

@palkan palkan added investigate Something is probably wrong question Further information is requested labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Something is probably wrong question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants