Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Wrong order for /blog page parts #318

Closed
fullofcaffeine opened this Issue Mar 13, 2013 · 7 comments

Comments

Projects
None yet
4 participants

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.

Owner

parndt commented Mar 13, 2013

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

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!

Owner

parndt commented Mar 15, 2013

I think for now manually edit and if this happens again please post
back. I'll leave this open for a while in the meantime.

Owner

ugisozols commented May 26, 2013

@fullofcaffeine can we close this?

@ugisozols ugisozols closed this Jul 16, 2013

linteau commented Aug 19, 2013

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

Owner

ugisozols commented Sep 4, 2013

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

Owner

ugisozols commented Sep 4, 2013

@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