Skip to content

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

Open
@andreas-it-dev

Description

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?

Metadata

Assignees

No one assigned

    Labels

    investigateSomething is probably wrongquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions