refinerycms-blog icon indicating copy to clipboard operation
refinerycms-blog copied to clipboard

I18n error when default_locale != :en

Open jerefrer opened this issue 10 years ago • 9 comments

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

jerefrer avatar Aug 02 '13 16:08 jerefrer

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

parndt avatar Aug 02 '13 21:08 parndt

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

jerefrer avatar Aug 03 '13 16:08 jerefrer

I didn't check it but it might be related to https://github.com/refinery/refinerycms/issues/2209.

ugisozols avatar Aug 04 '13 17:08 ugisozols

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).

jstcki avatar Jan 17 '14 17:01 jstcki

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

in8finity avatar May 19 '14 22:05 in8finity

Maybe related with #367

waiting-for-dev avatar Jun 19 '14 11:06 waiting-for-dev

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

jstcki avatar Jun 30 '14 11:06 jstcki

@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.

waiting-for-dev avatar Jun 30 '14 14:06 waiting-for-dev

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 ?

Plaristote avatar Jan 28 '15 17:01 Plaristote