开发者

Why won't my map generate after a render action? (Rails and YM4R/GM)

I am using markers on a map to show and update the position of a point model in my app. When the point is moved I have a javascript event which updates th开发者_如何学编程e position of said point.

This all works fine until some point model validation fails and the edit page rendered with errors. The map is gone. I understand that 'render' won't actually execute code in the controller like calling an action via redirect_to.

As a result I moved my map generation code from the controller to the points helper so this is the sort of thing I have in my view;

<% map = generate_map_for_point(point) %>
<% content_for :head do %>
 <% if map %>
  <%= GMap.header(:with_vml => false, :host => request.host) %>
  <%= map.to_html %> 
 <% end %>
<% end %>

This doesn't work either. Finally, I've made the form_for a remote_form_for and moved the map into a partial along with the map init javascript. Now the map init javascript isn't contained in the header but I still have the same problem...


I lie, in fact putting the map code in the helper appears to have resolved the problem. I'm sure it wasn't working before. Oh well, maybe I moved on to putting it in a partial to quickly and overcomplicated the situation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜