-
Notifications
You must be signed in to change notification settings - Fork 335
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
how to pass instance variables between templates? #363
Comments
Child can be given a block variable but it'll be |
At a minimum, I need a hack of a solution so I can keep moving. From within a template is there any object I can hook into that'll also be available in the next template? I'm thinking of just setting my own instance variable on something. |
Bah, didn't mean to do that. |
Well I think you could probably figure out a way to wrap the instance variable into the object in a more OO style... but if you have to hack it, you could probably pass something into the Rabl::Engine.new("...source...", { :format => "xml" }).render(scope, { :foo => "bar", :object => @user }) |
Yeah, I was thinking there is a shortcut but my typical response is to use a presenter. Here's my boilerplate response on why there should only be one object at the top of your RABL and why everything should derive from there: Great articles to read: I cover most of the above with Testing in isolation, example in RABL on my blog. After writing that, I recently read Objects on Rails and found that Avdi Grimm covers much of the same but explains it better in book format. |
Completely agree whenever I see multiple instance variables or really complex logic in nodes in rabl, I usually extract it into a PORO. A simple ruby object that acts as a presenter which can be tested easily and in isolation. On Nov 21, 2012, at 9:37 AM, David Sommers [email protected] wrote:
|
I've got users/show:
and accounts/show
If I do this:
Rabl::Renderer.json(user, 'users/show', :locals => {:test => 123})
the :foo attribute is nil in the accounts. Is there any way to pass an instance variable through to another partial?
The text was updated successfully, but these errors were encountered: