Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a new folder to asset path in rails 4

Tags:

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?

like image 723
mgh Avatar asked Apr 21 '14 06:04

mgh


1 Answers

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 :)

like image 85
Rajesh Omanakuttan Avatar answered Sep 19 '22 18:09

Rajesh Omanakuttan