Ruby on Rails - Make Slim the Default Template
Solution 1
You can use "slim-rails" gem which is built for generating slim template as default.
https://github.com/slim-template/slim-rails
Just replace gem 'slim'
by gem 'slim-rails'
in your Gemfile.
Solution 2
In you Gemfile, include
gem 'slim-rails'
And to generate slim tempage, in config/application.rb add this line of code
class Application < Rails::Application
........................................
config.generators do |g|
g.template_engine :slim
end
end
Related videos on Youtube
Ziyan Junaideen
I am Ziyan, a computer engineer from Colombo Sri Lanka. As a kid I wanted to be a pilot. I loved the suite and the idea of flying every day. Today I work as a freelance software engineer building awesome apps and the occasional sweeping the code to hunt bugs. I first taught my self VB in 2000. Later I learnt many languages thorough classes and books but nothing felt like the day I wrote my first line of Ruby. It was different and it was elegant and I instantly fell in love. Then recently came Node.js to my bag of tools. I used to invest my free time on learning some thing new. But am having to keep it at bay until July 2017 as I am interested in completing my website, writing some Ruby tutorials in Sinhalese. Then I intend to look in to mastering React native by doing a mobile app that I always wanted to build. Scala and Erlang would be in the pipeline, which are expected to be touched by the end of this year. I have been working on Ruby (introduced in my time with Orpiva.com team) for over 5 years. I believe Ruby is really great, it may not be as fast as I would like though. Today I work as an expert Ruby on Rails developer on UpWork. How about you?
Updated on September 15, 2022Comments
-
Ziyan Junaideen almost 2 years
I am working on a Ruby on Rails project and am needing to customize default views provided by Gems.
The requirement is to use Slim for template. I understand that ERB is the default template engine for Rails.
As per my observation, the priority is for ERB and if not it will use Slim/Haml views.
I am interested in knowing if it is possible to set Slim as the default instead of the ERB?
How can this be achieved so that when I create a local version of a template in Slim it will override the template provided by the gem.
Any clue will be appreciated.
-
Besi about 10 yearsIs there a way to add slim within
rails new MyProject
? -
Billy Chan about 10 years@Basi, when generating new project, there is no view so I don't think you need it. Also there is no Gemfile for adding the gem.
-
Besi about 10 yearsYou're right. However there is application.html.erb. But this is easy to change. Thanks for the comment.
-
Michał Szajbe about 10 years@Besi you could achieve this with application templates - guides.rubyonrails.org/rails_application_templates.html
-
Incerteza about 9 yearswhat's the difference between "slim" and "slim-rails"?
-
Incerteza about 9 yearswhat's the difference between "slim" and "slim-rails"?
-
Eric Hu over 8 years@アレックス It looks like "slim-rails" has "slim" has a dependency, but has additional code for configuring Rails generators.
-
Vetal4eg over 7 years@アレックス slim-rails for rails generates
-
Lori about 5 yearsThis got
rails generate controller
to generate slims instead of erbs, but how do I tell Puma to looks for slims instead of erbs?