Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces #1702 #1706

Merged
merged 4 commits into from
Jun 2, 2012
Merged

Replaces #1702 #1706

merged 4 commits into from
Jun 2, 2012

Conversation

parndt
Copy link
Member

@parndt parndt commented May 26, 2012

No description provided.

@parndt
Copy link
Member Author

parndt commented May 26, 2012

@joemsak I'd love your feedback on this and to know whether it fixes your problem too

@travisbot
Copy link

This pull request passes (merged 2a14afb9 into e32ba57).

@travisbot
Copy link

This pull request passes (merged 2a7f4a3 into e32ba57).


def rebuild_with_invalidate_cached_urls!
rebuild_without_invalidate_cached_urls!
find_each.each(&:invalidate_cached_urls)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the each call is redundant here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone explain when this gets called during update_positions in crud (calls class method rebuild! -- what is alias_method_chain doing here?)

and then what this rebuild_with/without method is doing? I'm a bit mystified by it.

I understand why my earlier method didn't need to iterate over children...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias_method_chain is a way of overriding a method but retaining the original version.

In this case alias_method_chain creates a method called rebuild_with_invalidate_cached_urls! and rebuild_without_invalidate_cached_urls!

The 'without' method is the original and the 'with' method is the new one that we've just defined. The first step is calling the the original and then we're calling our custom logic. This ensures that awesome_nested_set can still run its logic.

However, I can put a raise in this method and nothing fails suggesting that we're not testing that this method gets called at all. Fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention that under the hood rebuild! is now mapped (using alias_method to rebuild_with_invalidate_cached_urls! so calling Refinery::Page.rebuild! executes our new method instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phiggins you were quite correct; I have updated that.

@travisbot
Copy link

This pull request passes (merged 843346d into e32ba57).

@joemsak
Copy link
Contributor

joemsak commented May 27, 2012

Aha okay I totally get about 90% of what you said so thats good enough for me

+1 thanks for the hard work

@parndt
Copy link
Member Author

parndt commented May 28, 2012

So this code solves your problem?

@ugisozols
Copy link
Member

Why is this needed in the first place? I fail to reproduce a failing case. @joemsak?

@joemsak
Copy link
Contributor

joemsak commented May 28, 2012

Refinery 2.0.4:

Open to /refinery/pages

Re-sort a page to a new parent page

The original problem was that at this point, the admin edit link was invalid and produced a nil @page object

I "resolved" it by sticking to the primary key ID instead of the friendly id path in the edit URL constructor

The second problem that arose from fixing the first was that our public side submenu would show the page in the right spot but with the wrong URL, producing a 404 when clicked

Our submenu was using refinery.url_for(page.url) -- I'd have to dig to remember why but suffice to say we had to use that method to make page urls work both for pages with marketable urls (friendly id) and pages that have forwarding urls (link_url)

When admin/pages#update_positions is called through the action of clicking "done resorting pages" it's easiest to hook into the line that calls class method "rebuild!"

@ugisozols
Copy link
Member

I see the re-sort bug in backend now - thanks @joemsak!

Btw, it's still present. We need page reload or some kind of jquery stuff to change the url for edit link.

@joemsak
Copy link
Contributor

joemsak commented May 28, 2012

Youd have to have update_positions render the partial after rebuilding the urls but it's a shared crud.rb action so I'm sure it's tricky

@travisbot
Copy link

This pull request passes (merged 9adbd71 into e32ba57).

@parndt
Copy link
Member Author

parndt commented Jun 2, 2012

@ugisozols happy?

@ugisozols
Copy link
Member

Yes. Are you? :)

@parndt
Copy link
Member Author

parndt commented Jun 2, 2012

I generally have a positive outlook on life, yes.

Also I'm happy with this pull request but then it's mine..

ugisozols added a commit that referenced this pull request Jun 2, 2012
@ugisozols ugisozols merged commit ecfbfe8 into 2-0-stable Jun 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants