Layout that loads only for specific actions

Is there an easy way to have a piece of code or even an entire layout
that not only loads for a given controller, but only a given action on
that controller? Specifically, I’m trying to load a small Google Map
using their API, and I’ve written it to automatically geocode the
address based on an address value passed from the controller.

I have a controller called “events” that lists a bunch of upcoming
events, and when you select an event, a details page for that event is
invoked via the “details” action. The API only gets passed the address
for geocoding when “details” is loaded, but in its current state, it
also wants the address everywhere in the events controller, and since
it’s “nil” Rails gives me an error. I want to be able to only load the
map from the Javascript code when one action is invoked, not when the
whole “events” view is loaded. Is there an easy way to do this with
layouts?

(Sorry for the roundabout question, as I’m something of a newb when it
comes to programming and a total newb when it comes to RoR).

Thanks!

  • Coleman

If I’m understanding you right, you should be able to just do:
render :layout => ‘events’

Put that in the controller method for the action you want the layout
loaded for. Any other actions will still use the default layout for
that controller

  • Paul

On Jan 30, 3:53 pm, Coleman Mccormick <rails-mailing-l…@andreas-

crayz wrote:

If I’m understanding you right, you should be able to just do:
render :layout => ‘events’

Put that in the controller method for the action you want the layout
loaded for. Any other actions will still use the default layout for
that controller

  • Paul

On Jan 30, 3:53 pm, Coleman Mccormick <rails-mailing-l…@andreas-

You’re exactly right. I was just about to reply that I figured it out.
Pretty simple solution. Thanks a lot!