2015-10-18 25 views
1

我使用IMGkit宝石生成和保存文件到Rails的根文件夹中的文件夹public访问公用文件夹从IMAGE_TAG在Rails视图

我要显示在index认为图像。

我想是这样的

<%= image_tag "#{Rails.public_path}/#{current_user.email}.png" %> <br/>

但由于它产生localhost:3000/path/to/png-image而不是path/to/png-image在浏览器中不显示图像。

任何解决方法?提前致谢。

回答

1

如果您使用的是Rails 3.2+,我建议您将图像保存到“app/assets/images”文件夹中。

然后你可以使用这样的事情:

<%= image_tag "#{current_user.email}.png" %> 

您还可以使用子目录:

<%= image_tag "generated_images/#{current_user.email}.png" %> 

了解更多关于资产管道的位置: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

+0

让我试试这个@ woodenfox –

+0

谢谢@woodenfox。有用!!!。但有什么办法可以使公共文件夹的绝对URL? –

+0

您可以将/ public视为您的根文件夹。因此,上面提供的相同代码应该可以工作。 – woodenfox

相关问题