[RUBY] 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 along with Rails
How to get started with creating a Rails app
How to get started with Gatsby (TypeScript) x Netlify x Docker
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
Get started with DynamoDB with docker
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 scroll horizontally with ScrollView
Let's get started with parallel programming
How to use Java HttpClient (Get)
How to enclose any character with "~"
How to get values in real time with TextWatcher (Android)
How to get parameters in Spark
How to use mssql-tools with alpine
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
How to start Camunda with Docker
Easy code review to get started with Jenkins / SonarQube: Static analysis
[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 crop an image with libGDX
How to share files with Docker Toolbox
How to get date data in Ruby
How to compile Java with VsCode & Ant
[Java] How to compare with equals method
[Android] How to deal with dark themes
How to use BootStrap with Play Framework
[Rails] How to use rails console with docker
How to switch thumbnail images with JavaScript
[IOS] How to get data from DynamoDB
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 handle sign-in errors with devise
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 deal with Precompiling assets failed.
How to achieve file upload with Feign
How to run Blazor (C #) with Docker
How to build Rails 6 environment with Docker
How to deploy
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 <>>