Ruby on rails 如何在rails模型中获得完整的资源路径

Ruby on rails 如何在rails模型中获得完整的资源路径,ruby-on-rails,ruby,google-maps,gmaps4rails,Ruby On Rails,Ruby,Google Maps,Gmaps4rails,我在我的应用程序中使用了gmap4rails,它说要指定一个标记,您应该在模型中定义一个方法。但是我怎样才能得到完整的图像url呢 现在,我的模型中有以下代码 def gmaps4rails_marker_picture { "picture" => helpers.asset_path("marker.png"), "width" => 20, "height" => 33 } end def helpers ActionController::Base

我在我的应用程序中使用了
gmap4rails
,它说要指定一个标记,您应该在模型中定义一个方法。但是我怎样才能得到完整的图像url呢

现在,我的模型中有以下代码

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

def helpers
  ActionController::Base.helpers
end
但这只给了我一个图像的路径

我也试过这样做

Rails.application.routes.url_helpers.root_url + helpers.image_path("marker.png")
但这给了我一个错误:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
有什么办法可以让这一切顺利进行吗?

看看。 您需要设置Rails.application.routes.default\u url\u选项,或者将:host选项传递给root\u url(host:'foo.bar')
要为不同的环境设置不同的主机选项,您可以使用./config/environments/xx.rb文件

好吧,这对我很有用。我的意思是:config/environments/xx.rb和
Rails.application.routes.default\u url\u options[:host]=“localhost:3000”
,然后是
Rails.application.routes.url\u helpers.root\u url+ActionController::Base.helpers.image\u path(“marker.png”)
=>“http://localhost:3000//assets/marker.png“