Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Less files in Rails

I would like to ask how to use .less files in a Rails application if they are placed under assets but in a separate folder (let's call the folder "myless") from stylesheets. Another way to term this is that the myless folder would be side by side the folders, "images", "javascript" and "stylesheets" which are under the assets folder.

How do I import them to application.css or to a .CSS file? What lines of code would I use? Do I have to add a method in environment.rb? What gems do I have to use?

Any insight would be superb. Note that I am fairly new to Rails and are studying different tutorials on it. The different implementations in different versions of Rails is confusing me and there's not really a clear tutorial I can find online. I am currently trying to implement a bootstrap template, this is why I ask this question. I got the JavaScript and the CSS down but realized that the template uses .less files. Help?

like image 340
Catherine Austria Avatar asked Mar 16 '23 08:03

Catherine Austria


1 Answers

You can enable your app to support LESS by including the appropriate gem(s):

gem 'therubyracer'
gem 'less-rails'

Then run bundle install. Assuming you have the appropriate stylesheets included in your stylesheets manifest, you should be good to go!

There's also the rails-less-bootstrap gem if you want a simpler way of including Bootstrap in your project.

Note: it's a good idea to keep your stylesheets together. Instead of having the myless directory be on the same level as images, javascripts, and stylesheets, you should consider moving it inside of your stylesheets directory.

Hope it helps!

like image 88
Zoran Avatar answered Mar 19 '23 22:03

Zoran