开发者

Ym4r can't convert to string for rails3

开发者 https://www.devze.com 2023-01-08 22:48 出处:网络
Here\'s some 开发者_开发问答background of my problem: I am on Snow Leopard I have RVM installed(using a ruby1.9.2-head installation)

Here's some 开发者_开发问答background of my problem:

I am on Snow Leopard I have RVM installed(using a ruby1.9.2-head installation) I am using rails3 I installed the ym4r using this http://github.com/guilleiguaran/ym4r_gm (and followed the tutorial)

Anyway, I added these to my controller:

@map = GMap.new("map_div")
@map.control_init(:large_map => true,:map_type => true)
@map.center_zoom_init([75.5,-42.56],4)
@map.overlay_init(GMarker.new([75.6,-42.467],:title => "Hello", :info_window => "Info! Info!"))

then these to my view:

Test <%= raw(GMap.header) %>  <%= raw(@map.to_html) %>  <%= raw(@map.div(:width => 600, :height => 400)) %>  

well actually im using haml(does it matter?)

Test
= raw(GMap.header)
- unless @map.blank?
  = raw(@map.to_html)
#map{:style => "width: 600px; height: 400px"}

problem is i keep getting a

Showing /Users/eumir/rails_apps/evo-lux/app/views/layouts/_map.html.haml where line #11 raised:

can't convert Ym4r::GmPlugin::Variable to String (Ym4r::GmPlugin::Variable#to_str gives Ym4r::GmPlugin::Variable)

Extracted source (around line #11):

9: Test 10: = raw(GMap.header) 11: = raw(@map.to_html) 12: = raw(@map.div(:width => 600, :height => 400))

which is totally weird. I can't double check with debugger(it's another error altogether...my rails cant find ruby-debugger)

so im really kinda stumped. Any help?


The following function needs to be added to class Variable in mapping.rb of the plugin.

def to_str @variable + ";" end

Array#* gets called in the to_html function and Ruby 1.9.2 uses to_str instead of to_s to join the values.


Ok should've RTFM. Some discoveries:

  • the plugin was made for the now deprecated google maps v2 API
  • the to_html function of the plugin is a bit off in the sense that the init variables for the html variables is an array of variables - which are being joined by a string.
0

精彩评论

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