Rails 3:如何在控制器中获取图像路径?

问题描述:

要在控制器中获取图像路径,我使用以下方法:

To get the image path in Controller I use the following method:

class AssetsController < ApplicationController
  def download(image_file_name)
    path = Rails.root.join("public", "images", image_file_name).to_s
    send_file(path, ...)
  end
end

有没有更好的方法找到路径?

Is there a better method to find the path ?

ActionController::Base.helpers.asset_path('missing_file.jpg')

从 Rails 控制器访问资产路径