Creating non-english page first, english content second fails #1881

Closed
xyz opened this Issue Aug 14, 2012 · 12 comments

Projects

None yet

7 participants

@xyz
Contributor
xyz commented Aug 14, 2012

If I create page, with parent page, in non-english language, and then try to create english content for the same page, it fails with error. The funny thing is, it works as expected if I create english content first, then non-english. Also, if I create non-english page with no parent, it gives me no troubles creating english content. Unless I first set the parent, and then try to create :en content.

Its a pristine install with only this change in config/initializers/refinery/i18n.rb:

  • config.default_frontend_locale = :it
  • config.frontend_locales = [:it, :en]

Its the same for edge and latest stable (2.0.6).

Now, the error:

NoMethodError in Refinery::Admin::PagesController#update

undefined method `update_attributes' for nil:NilClass

Request

Parameters:

{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"dq1yUjTwiwOhsJlQKOR+orPa5SFri79fm3I2Avtmlk8=",
"switch_locale"=>"en",
"page"=>{"title"=>"Page A1",
"parts_attributes"=>{"0"=>{"body"=>"",
"position"=>"0",
"id"=>"6"},
"1"=>{"body"=>"",
"position"=>"1",
"id"=>"7"}},
"draft"=>"0",
"parent_id"=>"1",
"menu_title"=>"",
"skip_to_first_child"=>"0",
"link_url"=>"",
"show_in_menu"=>"1",
"browser_title"=>"",
"meta_keywords"=>"",
"meta_description"=>""},
"continue_editing"=>"false",
"path"=>"home/4",
"locale"=>:it}

Session dump:

_csrf_token: "dq1yUjTwiwOhsJlQKOR+orPa5SFri79fm3I2Avtmlk8="
refinery_return_to: "/refinery/pages/home/pagina-a1/edit"
return_to: "/refinery/pages"
session_id: "a32f9b25493d52909615a112b4cb981c"
warden.user.refinery_user.key: ["Refinery::User", [1], "$2a$10$8NcW7XKfFWrj3HbBLumN4u"]

Env dump:

GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate"
HTTP_ACCEPT_LANGUAGE: "en-us,en;q=0.5"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "localhost.localdomain"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"

Response

Headers:

None

@parndt
Member
parndt commented Aug 14, 2012

Is English your default_frontend_locale?

@xyz
Contributor
xyz commented Aug 15, 2012

No. This is what I do:

$ rails new refinerycms
$ cd refinerycms

(edit Gemfile)
gem 'refinerycms'
gem 'refinerycms-i18n'

$ bundle install
$ rails generate refinery:cms --fresh-installation

(edit config/initializers/refinery/i18n.rb)
config.default_frontend_locale = :it
config.frontend_locales = [:en, :it]

$ rails start

I create an account and am greeted with Italian welcome message. Then I try to create a child page for the Home page, enter just the title, and push Save. Success, I have an :it page. Now, trying to edit, I click on the :en flag, put the title, and get the error from the previous post when saving the page. Btw, I also noticed that when going :it -> :en the initial title is not showing. Not so when going the :en -> :it route.

If I, when creating a new subpage, first switch to :en - everything just works as expected (with one minor itch: switching the language looses the parrent page, although that can be set manualy). Also, If I create page with no parent, it works again, no matter which language I pick first. I can set the parrent page later, but being forced to go that way kills all the joy. :)

So, I got curious and tested with the default_frontend_locale unchanged - that is with the default value, which is set to :en. And the problem changed, too. Creating first :en, :it second works. But if I click for a new subpage, then switch to :it (again, it looses the parent page) it works only if I don't manualy set the parent page (leaving it empty). If I set the parent before saving, it gets saved, but I cannot edit it any more. And although it shows in the admin interface in Pages list hierarchy, it doesn't show on the site (nither in menu, nor the page itself). This is the error:

NoMethodError in Refinery/admin/pages#edit

Showing /home/xyz/.rbfu/rubies/1.9.3-p194/lib/ruby/gems/gems/refinerycms-pages-2.0.6/app/views/refinery/admin/pages/_form.html.erb where line #2 raised:

undefined method `persisted?' for nil:NilClass
Extracted source (around line #2):

1: <%= form_for [refinery, :admin, @page],
2:              :url => (refinery.admin_page_path(@page.uncached_nested_url) if @page.persisted?) do |f| %>
3:
4:   <%= render '/refinery/admin/error_messages', :object => @page, :include_object_name => true %>
5:
Trace of template inclusion: /home/xyz/.rbfu/rubies/1.9.3-p194/lib/ruby/gems/gems/refinerycms-pages-2.0.6/app/views/refinery/admin/pages/edit.html.erb

Nor can I delete it.

NoMethodError in Refinery::Admin::PagesController#destroy

undefined method `title' for nil:NilClass

I hope this is helpful. :)

@Tranquility
Contributor

@xyz execute rake db:seed should solve your problem.

@parndt parndt closed this in 559014a Aug 29, 2012
@parndt parndt added a commit that referenced this issue Aug 29, 2012
@parndt parndt update slugs if pages exist, otherwise do nothing.
Fixes #1910
Fixes #1881
af8b69d
@xyz
Contributor
xyz commented Aug 30, 2012

Sorry, but this commit hasn't changed anything (could it be that I'm doing something wrong? can't figure out what it is, though). Tried it again with refinery git repo updated and refinery gem pointing to the git repo (as per 'Upgrading to Edge' guide).

@Tranquility it doesn't. Btw, the following line does 'rake db:seed' automaticaly

$ rails generate refinery:cms --fresh-installation
@Tranquility
Contributor

It's true that the commit doesn't change anything about your problem. Your problem is that there is no slug for your default_frontend_locale so your not able to go to the edit path. That's why you need to run rake db:seed AFTER you changed your local settings. Because it creates the slugs for all languages you specified in config.frontend_locales.

@xyz
Contributor
xyz commented Sep 3, 2012

@Tranquility Well, I have run rake db:seed after the default_frontend_locale change, still getting the same error. I tried to remove db/development.sqlite3 and then ran rake db:migrate && rake db:seed. Didn't help.

@baol
baol commented Sep 16, 2012

This bug is still present in 2.0.8 with i18n 2.0.2

@ugisozols ugisozols reopened this Sep 25, 2012
@ugisozols
Member

I create an account and am greeted with Italian welcome message. Then I try to create a child page for the Home page, enter just the title, and push Save. Success, I have an :it page. Now, trying to edit, I click on the :en flag, put the title, and get the error from the previous post when saving the page. Btw, I also noticed that when going :it -> :en the initial title is not showing. Not so when going the :en -> :it route.

I can definitely reproduce ^

@chikamichi

Hi, same issue as xyz here.

@groe
groe commented Sep 28, 2012

Looks like #1461 to me.

@xyz
Contributor
xyz commented Sep 28, 2012

To me as well. And @gabpaladino's change seems to fix this.

@ugisozols
Member

Closing this because it's a dup of #1461. Let's keep discussion in one place.

@ugisozols ugisozols closed this Oct 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment