[RUBY] (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
[Rails] How to use Gem'rails-i18n' for Japanese support
[For Rails beginners] Summary of how to use RSpec (get an overview)
[For super beginners] How to use autofocus: true
How to implement login request processing (Rails / for beginners)
How to use GitHub for super beginners (team development)
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to use rails join
(For beginners) [Rails] Install Devise
[Rails] How to use validation
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[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 display error messages for comment function (for beginners)
[Rails] How to use gem "devise"
How to use StringBurrer and Arrays.toString.
[Rails] How to install Font Awesome
[Rails] How to use flash messages
How to use EventBus3 and ThreadMode
How to use Ruby on Rails
[Rails] How to install ImageMagick (RMajick)
[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
How to use \ t Escape sequences different for mac and Windows-java
How to install and use Composer on an ECS instance on Ubuntu 16.04
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
[Rails] How to introduce kaminari with Slim and change the design
[Tips] How to solve problems with XCode and Swift for beginners
How to use binding.pry for view files
How to use OrientJS and OrientDB together
How to use custom helpers in rails
Install Webpacker and Yarn to run Rails
[Ruby on Rails] How to use CarrierWave
[Rails] How to use rails console with docker
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
How to use MySQL in Rails tutorial
[Ruby on Rails] How to use redirect_to
[Note] How to use Rails 6 Devise + cancancan
[Ruby on Rails] How to use kaminari
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
How to build a Ruby on Rails environment using Docker (for Docker beginners)
[Rails] Articles for beginners to organize and understand the flow of form_with
[Java] How to use FileReader class and BufferedReader class
[Rails] Add page nation to table [For beginners]
[Rails] How to use select boxes in Ransack
How to use rails g scaffold, functions, precautions