Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

I18n error when default_locale != :en #342

Open
jerefrer opened this Issue · 9 comments

7 participants

@jerefrer

It seems there is an error with FriendlyId and Globalize3 when the app's default locale is set to something else than :en.

I've made an example app to demonstrate that (sqlite3 db included) : https://github.com/jerefrer/refinerycms-blog_i18n_error_proof

Failing test case :
1) Go to the admin blog index
2) Click fr_first blog post's english flag
3) Submit
4) Get undefined method 'update_attributes' for nil:NilClass

When I don't set the I18n default locale in config/application.rb to :fr everything seems to work just fine.

Should I simply not set it, as Refinery's have its frontend_locales ?
What do you think ?

PS : There's no such issue with Refinery's Pages

@parndt
Owner

Is this happening with the latest, latest master branch version?

@jerefrer

Yes it is : refinerycms at bdc0740 and refinerycms-blog at ddbd568.

@ugisozols
Owner

I didn't check it but it might be related to refinery/refinerycms#2209.

@herrstucki

I'm seeing a similar error.

  1. I create a new blog post in a different locale (e.g. es) than the default (en) and save.
  2. When I click the edit link in the admin panel, e.g. /refinery/blog/posts/blah/edit it sometimes works.
  3. When I click the flag edit link, e.g. /refinery/blog/posts/blah/edit?switch_locale=es it fails with
# in /app/views/refinery/blog/admin/posts/_form.html.erb
undefined method `model_name' for NilClass:Class

The log says

Processing by Refinery::Blog::Admin::PostsController#edit as HTML
  Parameters: {"switch_locale"=>"es", "id"=>"blah", "locale"=>:en}

and it tries to load a translation with the locale en

SELECT DISTINCT "refinery_blog_posts".id, published_at AS alias_0
FROM "refinery_blog_posts"
LEFT OUTER JOIN "refinery_blog_post_translations" ON "refinery_blog_post_translations"."refinery_blog_post_id" = "refinery_blog_posts"."id"
WHERE "refinery_blog_post_translations"."locale" IN ('en', 'es')
AND "refinery_blog_post_translations"."slug" = 'blah' 
AND "refinery_blog_post_translations"."locale" IN ('en') 
etc ...

Sometimes it works if I reload the url with the switch_locale parameter (e.g. /refinery/blog/posts/blah/edit?switch_locale=es).

@in8finity

It's still an issue. Exactly as described by Herrstucki.

@waiting-for-dev

Maybe related with #367

@herrstucki

I may have found the cause of this bug: In some cases (like the one described above), the slug doesn't get set in the translation table. This only appears to be a problem when it's missing in the default translation (in this case en), where this part of the query fails:

...
AND "refinery_blog_post_translations"."slug" = 'blah' 
AND "refinery_blog_post_translations"."locale" IN ('en')
...

When I set the slug in the affected row, everything works as expected.

Edit: I'm running the 2-1-stable version

@waiting-for-dev

@herrstucki I think at leas it is not my case. I have all the translations with the slug column set... My default locale is 'es' and also 'ca' is present.

@prokopsimek prokopsimek referenced this issue from a commit in prokopsimek/refinerycms-blog
@prokopsimek prokopsimek bugfix
Fixes: refinery#367
Maybe fixes: refinery#361 refinery#363 refinery#365 refinery#342

HOW TO FIX:
1) pull this fix
2) Start rails console (rails c)
3) In rails console run command:  ::Refinery::Blog::Post.find_each(&:save)

And it should be ok. It is for me...
d927ea8
@prokopsimek prokopsimek referenced this issue
Closed

bugfix #404

@prokopsimek prokopsimek referenced this issue from a commit in prokopsimek/refinerycms-blog
@prokopsimek prokopsimek bugfix
Fixes: refinery#367
Maybe fixes: refinery#361 refinery#363 refinery#365 refinery#342

HOW TO FIX:
1) pull this fix
2) Start rails console (rails c)
3) In rails console run command:  ::Refinery::Blog::Post.find_each(&:save)

And it should be ok. It is for me...
3f1b663
@prokopsimek prokopsimek referenced this issue from a commit in prokopsimek/refinerycms-blog
@prokopsimek prokopsimek bugfix
Fixes: refinery#367
Maybe fixes: refinery#361 refinery#363 refinery#365 refinery#342

HOW TO FIX:
1) pull this fix
2) Start rails console (rails c)
3) In rails console run command:  ::Refinery::Blog::Post.find_each(&:save)

And it should be ok. It is for me...
b57eebc
@Plaristote

Same issue.
There's a way of fixing this, by ensuring that the globalize! filter runs before the find_post filter in Refinery::Blog::Admin::PostsController (it's as simple as adding prepend_before_filter :globalize! after the call to crudify).

I don't think this solution is very elegant though. Should the globalize filter really run after find_post in the first place ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.