refinerycms-blog
refinerycms-blog copied to clipboard
I18n error when default_locale != :en
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 :
- Go to the admin blog index
- Click fr_first blog post's english flag
- Submit
- 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
Is this happening with the latest, latest master branch version?
Yes it is : refinerycms at bdc0740 and refinerycms-blog at ddbd568.
I didn't check it but it might be related to https://github.com/refinery/refinerycms/issues/2209.
I'm seeing a similar error.
- I create a new blog post in a different locale (e.g.
es
) than the default (en
) and save. - When I click the edit link in the admin panel, e.g.
/refinery/blog/posts/blah/edit
it sometimes works. - 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
).
It's still an issue. Exactly as described by Herrstucki.
Maybe related with #367
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
@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.
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 ?