I want to create a new folder in app/assets
, in this folder I have some file, each file have css folder and javascript folder, like the below given addresses:
app/assets/plugins/bootstrap/css/bootstrap.min.css
app/assets/plugins/bootstrap/js/bootstrap.min.js
I use below code to define css
file, but not true and rails cannot find and load bootstrap.min.css
:
<%= stylesheet_link_tag "bootstrap.min", media: "all", "data-turbolinks-track" => true %> <%= stylesheet_link_tag "../plugins/bootstrap/css/bootstrap.min", media: "all", "data-turbolinks-track" => true %>
How can I declare css
and javascript
from plugin
folder?
Note: When I want see the css
file in browser by this address:
http://localhost:3000/assets/plugins/bootstrap/css/bootstrap.min.css
I get below error: No route matches [GET] "/assets/plugins/bootstrap/css/bootstrap.min.css"
But for css file that exist in assets/stylesheets/
I can see css file in browser by enter address like top. Why the diffrent beetwin stylesheets
and plugins
directory?
In application.rb
, add the below lines:
config.assets.enabled = true config.assets.paths << Rails.root.join("app", "assets", "plugins", "bootstrap","css") config.assets.paths << Rails.root.join("app", "assets", "plugins", "bootstrap","js")
Then you will be able to access bootstrap.min.css and bootstrap.min.js in your browser,
i.e., http://localhost:3000/assets/bootstrap.min.css
/ http://localhost:3000/assets/bootstrap.min.js
That means you have added the above to the asset paths.
Now you can call it using stylesheet_link_tag
or javascript_include_tag
.
Hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With