The first thing you need to do is add a couple gems to the Gemfile. The slim gem tells Rails how to parse the Slim syntax. The slim-rails gem overrides the Rails generators for ERB and replaces them with Slim generators. Add these gems to your Gemfile as below:
1 2 | |
Then run bundle install to install the gems:
1
| |
Then generate a Homes controller with a show action by running the command below:
1
| |
Notice that the generated view ends in .slim, Rails has generated a slim file for us, courtesy of the slim-rails gem. Now let’s modify our routes file to set up a resource and add a root path. Open up your routes file (config/routes.rb) and modify it so that it looks somethings like:
1 2 | |
Now you are ready to play with Slim. Open up the show view for homes (app/views/homes/show.html.slim) and modify it so that it looks somethings like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Which translates to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
So far so good, That’s it! See ya! :)