On Oct 1, 2009, at 7:50 PM, [email protected] wrote:

Should just be @location = @event.location. You have a typo in that Locatios.find is plural instead of singular.

Ha!  That worked. :)


On Oct 1, 2009, at 8:39 PM, Cameron Pope wrote:

Bob -

Unless I'm not understanding your question, I think this is exactly what Partials were designed to do: let you keep a snippet of erb code to render locations with the rest of the views for locations and then let you call it from anywhere.

Right, and I'll probably shift to partial, but the catch when using render is that it does not execute the other controller's action code. So, if you have controller XYZ with action 'show' and a show.html.erb, "render XYZ/show" will choke if it depends on a variable set in action XYZ.show. So even a partial would have choked. The secret above is that "@location = @event.location" needs to be set in the show action of the Events controller, which i suppose is fine since I've defined the one-to-many association (an event must have a location) but it doesn't seem to me to be cleanly OO. (?)


Of course, as soon as I get the answer, I discover something else that works. From http://guide.rails.info/layouts_and_rendering.html:
----
Every partial also has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the :object option:

<%= render :partial => "customer", :object => @new_customer %>

Within the customer partial, the customer variable will refer to @new_customer from the parent view.
----
:|
I swear I read that section twice and didn't see that little tidbit.

So!  What I've got now is,
<%= render :partial => 'locations/location', :object => @event.location %>

after copying show.html.erb to _location.html.erb, and changed all the "@location.xyz" refs to "location.xyz" (eg: location.name, etc). That works!


I can actually feel myself getting smarter.  You guys are awesome.
Thanks!
Bob Campbell
_______________________________________________
Bdrg-members mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/bdrg-members

Reply via email to