Passing large amounts of Template Code into a variable?
I'm using the following to populate a series of markers on a Google map in Rails:
marker = GMarker.new(coords, :icon => home, :title => "home", :info_window => "Info Text Goes Here" )
I'm trying to customize the info window beyond the text and trying to pass a lot of info 开发者_运维知识库into it, but I'm not sure exactly how to do it beyond making a really long annoying string. What's the best strategy to pass a lot of formatted info in HTML/CSS? Partials of some sort?
Ahh well, I can't yet comment, but Andrew's code should work on the View, but not in your controller.
It all depends on how your are constructing your Google map markers. If you are generating them in your controller, you'll want to create a function that will return the text for you and pass that to your GMarker object.
If you are creating them via Javascript in the view, then you'll want to use a partial to load the information in.
Perhaps describe the problem further.
Anyway, Sorry to clutter up the answer space with a comment on Andrews answer. :D
Cheers!
Dustin
You should be able do something like this from your view:
marker = GMarker.new(coords, :icon => home, :title => "home", :info_window => render(:partial => 'info_window') )
Where you have a partial in the same folder named _info_window.html.erb
For some reason, using (render :partial) as an argument supplied to the Gmarker caused only the partial to be rendered. When I changed it to render_to_string it worked.
精彩评论