comfy / comfortable-mexican-sofa

ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
MIT License
2.72k stars 637 forks source link

Editing a child page resets it to child of root page #644

Open JustinLove opened 9 years ago

JustinLove commented 9 years ago

If I edit /sub/page the correct parent path is shown in the slug field, but only the root page can be selected in the parent field.

If I save the page, it is moved to a child of the root page (/page) I can edit it again and select the parent page; after pressing Update Page, the slug field is correct, but only the root page appears in the parent selector again.

1.12.8, rails 4.2.1

JustinLove commented 9 years ago

When I save a page with a parent other than root, the site root children_count is set to 0, which prevents the select from populating.

JustinLove commented 9 years ago

I think counter caches are being updated twice; values swing by two each time, and I'm seeing two incremental updates in the logs.

JustinLove commented 9 years ago

Looks like a Rails 4.2 bug; updating on both explicit and implicit counter caches.

rails/rails#19042

GBH commented 9 years ago

Could it also be related to #529 ?

JustinLove commented 9 years ago

The recommended work around (set has_many counter cache to an invalid column) doesn't seem to work.

Counter caches seem to be updated from both the association helpers via BelongsToAssociation and via belongs_to_counter_cache_after_update upon save. Why both is beyond me.

This might be a more relevant PR: rails/rails#14849

I think I'm just going to have to patch counter cache out of page entirely - slow but at least it's right.

GBH commented 6 years ago

Super old. Closing it unless it pops up with Rails 5.2 again.

JohnSmall commented 5 years ago

It's popped up in Rails 5.2 again. I was just about to raise an issue and saw it was an old issue that's come back.

My workaround is simple;- 1) Edit the child page and save. It'll automatically be set to have the home page as parent. 2) Edit the child page again, this time reset the parent page to what it was before, then save.

When the page is a child of home then all the other pages are listed in the parent drop down so you can select the right one to get back to as before.

If the parent is a non-home page, then when you edit only the home page is available in the parent drop down, so when you save it that's what gets saved.

My guess is that it's a problem populating that drop down.

I'm using Comfy 2.0.17 in Rails 5.2.1

AdnanTheExcellent commented 3 years ago

I'm having the same issue. when i create a child page (in my case 3 levels deep from root), the child page parent gets reset to root on save

I'm on CMS 2.0.19 and rails 5.2.4.4

AdnanTheExcellent commented 3 years ago

For me, its because i was creating subclassses of Comfy::Cms::Page (i.e. Comfy::Cms::Page::Product). this line would always set to root

    # BUG: https://github.com/rails/rails/issues/14369
    # It's still a bug. Remove it to see failing test
    def parent_id=(id)
      self.parent = self.class.find_by(id: id)
    end

found here: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/extensions/acts_as_tree.rb#L111

the problem is self.class is not the parent class. Is that an assumption that can be made? I'm not sure if a Comfy::Cms::Page can be assigned to a different class within this gem? In my case I'm trying to assign a Comfy::Cms::Page::Product to a Comfy::Cms::Page::Category. My scenario is outside of the scope of the gem, but that method is less robust than I'd like it to be.

@GBH is that code still necessary? i see it reference an old bug thats supposed to be fixed in rails 4.0