3

I'm using gmap4rails in my application which says to specify a marker you should define a method in your model. But how can i get full image url for that?

Now I have the following code in my model

def gmaps4rails_marker_picture
{
  "picture" => helpers.asset_path("marker.png"),
   "width" => 20,
   "height" => 33
}
end

def helpers
  ActionController::Base.helpers
end

But this only give me path for an image?

I've also tried to do it like this

Rails.application.routes.url_helpers.root_url + helpers.image_path("marker.png")

but that gives me an error:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

Any way to make this work?

4

1 回答 1

-2

Look at How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis. You need to set Rails.application.routes.default_url_options or to pass :host option to root_url(host: 'foo.bar') To set different host option for different environments you can use ./config/environments/xx.rb files

于 2013-08-13T09:09:51.163 回答