admin管理员组文章数量:1425691
I am running a development server and I'm trying to load some static pages and files (images, css and javasripts) in my rails application for testing. (In general, I'm new in rails. The Rails installation has been done on Linux subsystem in Windows 10).
Although I have placed the files in assets/images
, assets/javascripts
and assets/stylesheets
I couldn't manage to read these files in my test apprication when server runs. I receive the following errors almost for all files I have added:
ActionController::RoutingError (No route matches [GET] "/assets/javascripts/jquery.min.js"):
ActionController::RoutingError (No route matches [GET] "/assets/javascripts/bootstrap.min.js"):
ActionController::RoutingError (No route matches [GET] "/assets/javascripts/jqBootstrapValidation.js"):
and for images
ActionController::RoutingError (No route matches [GET] "/assets/images/portfolio/dreams-preview.png"):
The same applies for some css files also (not all).
I tried several ideas I found here in order to solve this but I had no luck. I tried to setup:
config.serve_static_files = true
in development.rb
and
rake assets:prepile
Obviously, these files are not visible by rails application but I still don't understand what I have to do to make them visible. Can you please help me on this?
I am running a development server and I'm trying to load some static pages and files (images, css and javasripts) in my rails application for testing. (In general, I'm new in rails. The Rails installation has been done on Linux subsystem in Windows 10).
Although I have placed the files in assets/images
, assets/javascripts
and assets/stylesheets
I couldn't manage to read these files in my test apprication when server runs. I receive the following errors almost for all files I have added:
ActionController::RoutingError (No route matches [GET] "/assets/javascripts/jquery.min.js"):
ActionController::RoutingError (No route matches [GET] "/assets/javascripts/bootstrap.min.js"):
ActionController::RoutingError (No route matches [GET] "/assets/javascripts/jqBootstrapValidation.js"):
and for images
ActionController::RoutingError (No route matches [GET] "/assets/images/portfolio/dreams-preview.png"):
The same applies for some css files also (not all).
I tried several ideas I found here in order to solve this but I had no luck. I tried to setup:
config.serve_static_files = true
in development.rb
and
rake assets:prepile
Obviously, these files are not visible by rails application but I still don't understand what I have to do to make them visible. Can you please help me on this?
Share Improve this question edited Nov 10, 2016 at 8:02 Kirkos asked Nov 8, 2016 at 10:37 KirkosKirkos 351 gold badge2 silver badges9 bronze badges2 Answers
Reset to default 2You need to include these files in application.js manully or just write //= require_tree .
to load all js
Similarly, you have to work for css. Add *= require_tree .
in application.css
.
Finally, in order to resolve this error and transfer my static pages to Rails I had to modify my homepage.html.erb
as follows:
Stylesheet links:
<%= stylesheet_link_tag "bootstrap.min.css" %>
the following also works:
<link href="assets/bootstrap.min.css" rel="stylesheet">
Javascript include:
<%= javascript_include_tag "bootstrap.min.js" %>
In general, I found that no prepilation is necessary. I tested and it works with or without prepilation. The following also works:
<script src="assets/bootstrap.min.js"></script>
Tag for images:
<%= image_tag("portfolio/dreams-preview.png", class: "img-responsive img-centered") %>
Rails use by default the normal path for images (assets/images
). The full path should not be used. Unless the path for images is different, use only the path deeper than assets/images
, if exists.
No changes were made in application.html.erb
but prepilation for javascripts and stylesheets is necessary in assets.rb
:
Rails.application.config.assets.prepile += ['agency.min.js', 'agency.min.css', ...]
Eventually the site works, although some conflicts in the execution of javascripts might be appear.
本文标签: cssActionControllerRoutingError (No route matches GET quotassetsjavascriptsStack Overflow
版权声明:本文标题:css - ActionController::RoutingError (No route matches [GET] "assetsjavascripts - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745401197a2657046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论