admin管理员组文章数量:1420205
I have a web based app with the back-end build on Rails 5. I am using AngularJS for the front end. I am not using Asset Pipeline to serve any static content, all my scripts(JS&CSS) are loaded in the index.html file located in the public directory
and from there I'm using angular's ng-route to further manage the location.
The problem arises when in one of my HTML page I need to include an image using the HTML image tag, the problem is that the server cannot find the image file.
<img src="assets/images/logo.jpg" style="padding-bottom:20px;" />
I tried keeping my image both in app/assets/images
and public/assets/images
directory but on all the instances I get routing error stating no route found in my rails server console.
Referring to several stack overflow answers I tried this line in my config development.rb file :
config.public_file_server.enabled = true
But it didn't work. So how can I have served images without using the Rails Assetpipeline?
I have a web based app with the back-end build on Rails 5. I am using AngularJS for the front end. I am not using Asset Pipeline to serve any static content, all my scripts(JS&CSS) are loaded in the index.html file located in the public directory
and from there I'm using angular's ng-route to further manage the location.
The problem arises when in one of my HTML page I need to include an image using the HTML image tag, the problem is that the server cannot find the image file.
<img src="assets/images/logo.jpg" style="padding-bottom:20px;" />
I tried keeping my image both in app/assets/images
and public/assets/images
directory but on all the instances I get routing error stating no route found in my rails server console.
Referring to several stack overflow answers I tried this line in my config development.rb file :
config.public_file_server.enabled = true
But it didn't work. So how can I have served images without using the Rails Assetpipeline?
Share Improve this question edited Jun 11, 2017 at 8:48 Arghavan 1,1251 gold badge11 silver badges17 bronze badges asked Jun 11, 2017 at 8:27 ParasParas 3,52110 gold badges46 silver badges82 bronze badges 2-
Try giving
<img src="/assets/logo.jpg" style="padding-bottom:20px;" />
instead of<img src="assets/images/logo.jpg" style="padding-bottom:20px;" />
– Pavan Commented Jun 11, 2017 at 8:30 - Tried that as well, it did not worked. localhost:3000/assets/images/logo.jpg – Paras Commented Jun 11, 2017 at 8:47
1 Answer
Reset to default 5To serve images without using the asset pipeline, put your images in the public
directory.
An image at your_app/public/images/logo.jpg
is referenced using <img src="/images/logo.jpg
in your view.
Rails also provides a helper method for this, which generates the same code but provides some additional Rails features:\
<%= image_tag('/images/logo.jpg') %>
Again, you omit the public
part of the path. Furthermore, I'd advise against having a directory in public
called assets
- that will get overridden by the asset pipeline. It'll also confuse you. I'd change that directory name to something else.
本文标签: javascriptHow to serve static image in Rails 5 without using Asset PipelineStack Overflow
版权声明:本文标题:javascript - How to serve static image in Rails 5 without using Asset Pipeline? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745325352a2653566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论