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::ArgumentError with i18n v0.8.2+ #415

Closed
cbeer opened this issue May 30, 2017 · 5 comments
Closed

I18n::ArgumentError with i18n v0.8.2+ #415

cbeer opened this issue May 30, 2017 · 5 comments

Comments

@cbeer
Copy link

cbeer commented May 30, 2017

Steps to reproduce

https://gist.github.com/cbeer/140cb717506e97181644c59faaef92b2

Using i18n v0.8.2+, calling unauthorized_message causes an exception.

Upstream, they introduced a new check in 0.8.2: ruby-i18n/i18n#236.

Cancancan is explicitly passing a nil key:

message = I18n.translate(nil, variables.merge(scope: :unauthorized, default: keys + ['']))
.

Expected behavior

The unauthorized message should be provided.

Actual behavior

An exception is thrown:

I18n::ArgumentError: I18n::ArgumentError
    /Users/cabeer/.gem/ruby/2.4.1/gems/i18n-0.8.3/lib/i18n.rb:152:in `translate'
    /Users/cabeer/.gem/ruby/2.4.1/gems/cancancan-2.0.0/lib/cancan/ability.rb:226:in `unauthorized_message'

System configuration

Rails version: 5.0.2

Ruby version: 2.3.4

CanCanCan version 1.17.0

@radar
Copy link

radar commented May 31, 2017

I have just released I18n 0.8.4 which should fix this issue. Please try it out :)

@clemens
Copy link
Contributor

clemens commented May 31, 2017

This might be just my opinion but I think it's more CanCanCan's fault than i18n's: A call to I18n.translate with nil doesn't semantically make sense. It literally says "Give the translation of nothingness". I think what CanCanCan means to do here is use a fallback chain, but it takes a shortcut by piggybacking on the default option. What it should instead do is build up an array of potential keys and then shift off the first element as the starting key – similar to what simple_form does here: https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/inputs/base.rb#L173-L189. Then i18n could be fixed accordingly as well.

@coorasse
Copy link
Member

I agree with @clemens , PR is welcome!

@coorasse
Copy link
Member

coorasse commented Jul 4, 2017

is the problem with i18n solved now @cbeer ?

@clemens
Copy link
Contributor

clemens commented Jul 4, 2017

I guess it is solved by the i18n update but (IMO) it's not fixed in the right way ...

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

No branches or pull requests

4 participants