(For beginners) [Rails] Time saving tech! How to install and use slim

Introduction

I will explain how to install and use the Ruby template engine slim: relaxed: In Rails, I write html in a file called html.erb, but it is a little troublesome to fill in<h1> </ h1>and<%%>every time. With slim, you can write html more concisely and reduce the development effort.

1. slim introduction method

gem 'slim-rails'
#Gem for using slim with rails

gem 'html2slim'
# html.erb html.Gem to convert to slim
bundle install

bundle exec erb2slim app/views app/views

bundle exec erb2slim app/views app/views -d
git log
#Examine the hash value
git reset --hard hash value
#The hash value that came out--Enter after hard to return to the specified commit.

2. slim writing

List the basic usage of slim.

How to write <%%>


<% if %>

- if

How to write <% =%>


<%= puts hoge %>

= puts hoge

How to write text


<p>hoge<p>

p 
 | hoge

How to write a heading tag

<h2>hogehoge</h2>

h2 hogehoge

How to write id


<div id = id></div>

# id

How to write a class

<div class = hoge></div>

.hoge

How to write a comment


<!-- hoge -->

/hoge

If you compare html and slim, you can see that it is very simple to write.

Reference article

If you would like to know more detailed information, please refer to the following URL.

https://qiita.com/ngron/items/c03e68642c2ab77e7283

https://techacademy.jp/magazine/10172

Recommended Posts

(For beginners) [Rails] Time saving tech! How to install and use slim
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
[Ruby] How to use slice for beginners
[For Rails beginners] Summary of how to use RSpec (get an overview)
[For super beginners] How to use autofocus: true
How to use GitHub for super beginners (team development)
[Rails] How to use validation
[Rails] How to use authenticate_user!
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
Procedures for passing RealmObject to Fragment and how to use Parceler
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
[Introduction to Rails] How to use render
How to install Swiper in Rails
[Ruby on Rails] How to use redirect_to
[Note] How to use Rails 6 Devise + cancancan
How to use substring and substr methods
[Rails] How to use video_tag to display videos
[Rails] How to use helper method, confimartion
How to use credentials.yml.enc introduced in Rails 5.2
How to use @Builder and @NoArgsConstructor together
[For beginners] How to debug in Eclipse
[Rails] Articles for beginners to organize and understand the flow of form_with
How to use scope and pass processing (Jakarta)
How to use JQuery in js.erb of Rails6
How to build API with GraphQL and Rails
[Rails] How to get success and error messages
[Rails] How to use PostgreSQL in Vagrant environment
[Rails] How to convert UC time display to Japanese time display
[Java] How to use Calendar class and Date class
[Rails] How to edit and customize devise view and controller
How to install Gradle and Kotlin with SDKMAN (Mac)
(Ruby on Rails6) How to create models and tables
Beginners use ubuntu in windows to prepare rails environment
How to use and apply Java's JFrame / Canvas class
How to study kotlin for the first time ~ Part 2 ~
How to study kotlin for the first time ~ Part 1 ~
How to use identity
How to install MySQL
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
Super easy in 2 steps! How to install devise! !! (rails 5 version)
[Swift] How to install Firebase ~ How to use Realtime Database & Cloud Firestore
Options for rails new and settings to be done after rails new
Tutorial to create a blog with Rails for beginners Part 2
How to install Web application for each language in Nginx
How to run React and Rails on the same server
[Java] Use ResolverStyle.LENIENT to handle the date and time nicely
How to install PHP 7.4 and SQL Server drivers in CentOS 7.7
For Java beginners: List, Map, Iterator / Array ... How to convert?
[Rails 5] How to use gem gon ~ How to pass variables from Rails to JS ~
Measures for taking a long time to load images (Rails)
How to create and launch a Dockerfile for Payara Micro
Tutorial to create a blog with Rails for beginners Part 0
[Tips] How to solve problems with XCode and Swift for beginners
Java for beginners, expressions and operators 1
Java for beginners, expressions and operators 2
Classes and instances Java for beginners
Util to use for some reason
(For beginners) [Rails] Time saving tech! How to install and use slim
[Rails] Articles for beginners to organize and understand the flow of form_with
(For super beginners) Getter / setter and property to think in D language