Rails 3:如何在控制器中获取图像路径? [英] Rails 3: How to get image path in Controller?

查看:44
本文介绍了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 控制器访问资产路径

这篇关于Rails 3:如何在控制器中获取图像路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆