How to get started with slim

slim installation

Install slim in the app folder.

gem install slim

With this, slim files with the extension .html.slim will be converted as .html.erb that you usually use.

gem install html2slim

With this, it seems that it will be possible to convert from html.erb to html.slim.

bundle exec erb2slim app/views app/views

If you get an error with this, add the following two sentences to the gemfile and bundle install.

gem 'slim-rails'
gem 'html2slim'
bundle install

This will delete the original erb file in the view folder.

bundle exec erb2slim app/views app/views -d

In order to automatically create a slim file in the future, It is OK if you specify slim as follows for config in config / application.rb.


module App
  class Application < Rails::Application
    config.generators.template_engine = :slim #Change to slim

Preparation before displaying slim file

rails g controller tweets

There is a tweets folder in the view folder. Create a new file called index.html.slim in it. Write something in the file for clarity.


Hello, world!

Add an index action inside the controller.


class ArchivesController < ApplicationController
	def index

Next is routing.


Rails.application.routes.draw do
  root "tweets#index"

Reboot the server and view the page

Don't forget to restart the server. If you do not restart, you will get an error like "ArchivesController # index is missing a template for request formats: text / html".


Reference article

Recommended Posts

How to get started with slim
[Note] How to get started with Rspec
How to get started with Eclipse Micro Profile
How to get started with JDBC using PostgresSQL on MacOS
I tried to get started with WebAssembly
Get started with Gradle
Rails beginners tried to get started with RSpec
How to get resource files out with spring-boot
Get started with Spring boot
How to number (number) with html.erb
How to update with activerecord-import
I tried to get started with Spring Data JPA
Get started with "Introduction to Practical Rust Programming" (Day 3)
How to get jdk etc from oracle with cli
How to enclose any character with "~"
How to get values in real time with TextWatcher (Android)
How to get parameters in Spark
Now is the time to get started with the Stream API
I tried to get started with Swagger using Spring Boot
Memo to get with Struts2 + Ajax
[Rails] How to introduce kaminari with Slim and change the design
How to get boolean value with jQuery in rails simple form
How to install Adopt OpenJDK on Debian, Ubuntu with apt (-get)
How to compile Java with VsCode & Ant
[Android] How to deal with dark themes
How to use BootStrap with Play Framework
How to switch thumbnail images with JavaScript
How to do API-based control with cancancan
[Java] How to get the current directory
How to achieve file download with Feign
How to update related models with accepts_nested_attributes_for
How to set JAVA_HOME with Maven appassembler-maven-plugin
How to implement TextInputLayout with validation function
How to get the date in java
How to delete data with foreign key
How to test private scope with JUnit
How to monitor nginx with docker-compose with datadog
How to achieve file upload with Feign
How to run Blazor (C #) with Docker
How to build Rails 6 environment with Docker
Get started with "Introduction to Practical Rust Programming" (Day 4) Call Rust from Ruby
[Java] [ibatis] How to get records of 1-to-N relationship with List <Map <>>
[Rails] How to get the user information currently logged in with devise
How to mock each case with PowerMock + Mockito1x
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to save to multiple tables with one input
How to get a heapdump from a Docker container
How to test interrupts during Thread.sleep with JUnit
How to use built-in h2db with spring boot
How to use Java framework with AWS Lambda! ??
How to get Class from Element in Java
How to get today's day of the week
How to create multiple pull-down menus with ActiveHash
How to use Java API with lambda expression
Getting started with Kotlin to send to Java developers
Maybe it works! Let's get started with Docker!
How to insert all at once with MyBatis
[Java] How to get random numbers excluding specific numbers
How to get and study java SE8 Gold
Try to get redmine API key with ruby
How to write test code with Basic authentication