在初始化程序中生成图像URL

时间:2013-10-18 04:43:12

标签: ruby-on-rails ruby image asset-pipeline

如何从初始化程序生成图像网址?我正在尝试调整this gem的配置,以便在其配置中设置默认图像。我想通过资产系统来引用它,以便它在开发和生产中起作用。我实际上是第一次尝试让它在生产模式下工作,但我也无法使其工作。

到目前为止,这是我一直在攻击的内容。

class DefaultGravatarImage
  include Rails.application.routes.url_helpers
  include ActionView::Helpers::AssetUrlHelper
  default_url_options[:host] = Rails.configuration.host

  def initialize(image_name)
    @image_name = image_name
  end

  def to_s
    path_to_image(@image_name)
  end
end

GravatarImageTag.configure do |config|
  config.default_image = DefaultGravatarImage.new("default_avatar.png").to_s
end

0 个答案:

没有答案