-
Notifications
You must be signed in to change notification settings - Fork 22
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
Establish working pattern for rendering partials from an exhibit with a freshly exhibited object. #51
Conversation
This is a shortcut for calling `my_exhibited_object.exhibit(to_model)` ... which is needed when passing an exhibited object through a `render` call as a local variable.
See: http://keepachangelog.com/ for rationale.
👍 on the changelog. I hate to ask, but will you do that minimal working code sample? If we can, I would rather fix it in the general sense rather than have a re-exhibit. If not, then we have to provide some workaround, so this would be it. Don't rush on the sample code -- I won't be able to work on it until next week. And then I'll fork your repo and send you a PR if I can find a solution, which we can then merge into this one. |
That would be fantastic. I'll devote a little time next week as well. Thank you! |
After going over it for a while, it seems to me there's little we can do to fully protect this bug... but first let me explain what I found. Basically, when you call a method on an exhibited object, then Now, since the user is free to bypass the DisplayCase::Exhibit#render method (which I'd always done -- see def render(template, options = {})
template.render(options.reverse_merge(:partial => to_partial_path, :object => self))
end to: def render(template, options = {})
template.render(options.reverse_merge(:partial => to_partial_path, :object => reexhibit))
end This solves the original problem by ensuring that the object within the partial has the full exhibit chain and is not narrowed down to just the Exhibit type that was just rendered. I'm going to pause my work on this here to give you time to catch up next week. Maybe you can invalidate my original assumption on the key "issue" here. Thanks again and see you next week! |
No, I think you're right. But here's what I'd like to see as a fix, if you think it will still work:
Thoughts? |
Can't just call The rest sounds great and I'm happy to take a crack at updating the README, etc. |
Sorry, I did mean that we'd call |
I meant to thank you for the test app too. That was freaking fantastic and made it so easy to follow along. I really appreciate that. |
Ahh, OK. So I'll make the changes to the pull request as per your outline. You bet, the test app was a little extra work, but I agree... it clarified the whole issue for me as well :). |
Alrighty, there it is. My wording may not be the clearest so please fix up as you see fit or let me know if I can contribute anything more. Cheers! |
Thanks @pdobb I'll see about fixing up the build before merging. |
Thanks a ton for your help @pdobb! I also released version 0.1.1 up to RubyGems, hurray! 🎆 |
👍 Thanks! Don't forget to change the "Unreleased" header in the changelog to v0.1.1 then, too :) |
OOOPS, thanks for reminding me! |
The need for this isn't easy to explain... and this pull request isn't necessarily what's needed (maybe there's an opportunity to automatically "reexhibit" objects). But this pull request is at least one way to present the issue I've run into along with the quick/easy solution that's been working for me for the past 6 months each time I run into it: the DisplayCase::Exhibit#reexhibit method.
By code example:
I hope this makes sense. The essence of it is that after performing a
render
call, the objects being passed through on the locals hash no longer behave as exhibits should. That is, normally exhibited objects find the first exhibited object that can respond to a method. But after going through a render they only respond to methods on the exhibited object that was passed in, unless reexhibited first.Also, I was trying to write tests for this example and was having trouble again. Trying to get an exhibited object to go through a
render
call seems like it would require adding a development dependency on Rails and I wasn't sure how to approach it even. And mocking didn't seem able to reproduce the issue.It desired, I'll try to set up a simplest case working code example... let me know.
I also started a CHANGELONG.md file for the project, so if nothing else maybe you'd like to take that part away from this :).