Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Wrong order for /blog page parts #318

Closed
fullofcaffeine opened this Issue · 7 comments

4 participants

Marcelo de Moraes Serpa Philip Arndt Uģis Ozols linteau
Marcelo de Moraes Serpa

Page parts for blog posts are being returned in reverse order on my production server. See below:

parts.each do |part|
(rdb:1) p parts
[#<Refinery::PagePart id: 6, refinery_page_id: 4, title: "Body", body: nil, position: nil, >created_at: "2012-05-02 00:23:16", updated_at: "2012-05-02 00:23:16">, #><Refinery::PagePart id: 7, refinery_page_id: 4, title: "Side Body", body: nil, position: nil, >created_at: "2012-05-02 00:23:16", updated_at: "2012-05-02 00:23:16">]

And on the production server, I get this, for the same page:

/gems/refinerycms-pages-2.0.9/lib/refinery/pages/content_page_presenter.rb:33
parts.each do |part|
(rdb:1) p parts
[#<Refinery::PagePart id: 7, refinery_page_id: 4, title: "Side Body", body: nil, position: nil, >created_at: "2013-01-27 18:38:57", updated_at: "2013-01-27 18:38:57">, #><Refinery::PagePart id: 6, refinery_page_id: 4, title: "Body", body: nil, position: nil, >created_at: "2013-01-27 18:38:57", updated_at: "2013-01-27 18:38:57">]

You can see that on production, the "SideBody" page part comes before the "Body" part.

Those parts don't have a position value set, but for some reason on my production server, it just returns the "Side Body" first. This brakes my layout, since it directly affects the DOM order.

I could temporarily fix it by adding a sort before the each call, in refinerycms-pages-2.0.9/lib/refinery/pages/content_page_presenter.rb:

31 def add_page_parts(parts)
32
=> 33 parts.sort.each do |part|
34 add_section PagePartSectionPresenter.new(part)
35 end
36 end

Is that a bug or am I doing something wrong?

Thanks in advance,

Marcelo.

Philip Arndt
Owner

The fact that they have no position means it is likely you've done something wrong. How did you add these parts? Try the following using rails console:

Refinery::Page.find_each do |page|
  page.reposition_parts!
end

Here's the code you're executing:

# Repositions the child page_parts that belong to this page.
# This ensures that they are in the correct 0,1,2,3,4... etc order.
def reposition_parts!
  reload.parts.each_with_index do |part, index|
    part.update_attributes :position => index
  end
end
Marcelo de Moraes Serpa

Hi parndt,

Thank you for the reply.

How did you add these parts?

I haven't. Refinerycms-blog did through its seed file, I think. I have no idea why it doesn't have a position.

Try the following using rails console:

I just ran it, but the issue is still there - side_body still comes before body for the /blog page.

Now, I'm still pretty naive with refinery, and I'm learning everyday. There are two things I can think of I could do (from the top of my head) that would solve the issue:

  • Manually edit the position for those parts;
  • Add a sort at as I suggested in the first post.

I will just edit the page part position fields for now, but I'd really like to understand why this happened. Did I miss a running seed task for refinerycms-blog or something?

EDIT: I just fetched the same parts in the console, and I noticed the code I ran earlier (reposition_parts!) did set the position for them, but in the wrong order:

=> [#<Refinery::PagePart id: 7, refinery_page_id: 4, title: "Side Body", body: nil, position: 0, created_at: "2013-01-27 18:38:57", updated_at: "2013-03-15 05:45:23">, #<Refinery::PagePart id: 6, refinery_page_id: 4, title: "Body", body: nil, position: 1, created_at: "2013-01-27 18:38:57", updated_at: "2013-03-15 05:45:24">]

Thanks!

Philip Arndt
Owner
Uģis Ozols
Owner

@fullofcaffeine can we close this?

Uģis Ozols ugisozols closed this
linteau

This is happening to me as well.

On the blog page, the side body appears before the body tab. This also causes the posts to be rendered under the RSS feed and Other Posts sections.

How can I manually edit the positions?

screen shot 2013-08-20 at 3 25 07 am

Uģis Ozols
Owner

@linteau this issue should be fixed by the commit above.

Uģis Ozols
Owner

@linteau here's how I would reposition parts manually using rails console:

# get blog page
blog_page = Refinery::Page.where(:link_url => "/blog").first

# find out in what order page parts are being returned
blog_page.parts.pluck(:title)

# if previous query returned ["Side Body", "Body"] then run this
blog_page.parts.sort.each_with_index do |part, index|
  part.position = index
  part.save!
end
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.