Rails Slim


Slim is template language which works with Rails3, 4.
It makes view codes simple.

Install and Apply your project

Add following description to your project Gemfile

# Slim
gem 'slim-rails'

You can use it after running bundle install

How to change from erb to slim

File name is


<p id="notice"><%= notice %></p>

<h1>Listing Products</h1>

      <th colspan="3"></th>

    <% @products.each do |product| %>
        <td><%= product.name %></td>
        <td><%= product.description %></td>
        <td><%= product.price %></td>
        <td><%= product.discontinued %></td>
        <td><%= link_to 'Show', product %></td>
        <td><%= link_to 'Edit', edit_product_path(product) %></td>
        <td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
    <% end %>


<%= link_to 'New Product', new_product_path %>
p#notice = notice

h1 Listing Products For Slim

      th Name
      th Description
      th Price
      th Discontinued
      th colspan="3"
    - @products.each do |product|
        td = product.name
        td = product.description
        td = product.price
        td = product.discontinued
        td = link_to 'Show', product
        td = link_to 'Edit', edit_product_path(product)
        td = link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' }

= link_to 'New Product', new_product_path

If there are erb and slim at the same directory,
.erb is prior.
So if you want to use slim, please delete same name erb file.


html2slim is a tool to convert from html to slim, erb to slim.
Install it and we can use html2slim and erb2slim
Install command is

gem install html2slim

How to convert?

erb2slim show.html.erb show.html.slim

This is not perfect, so we need to check whether this is converted correctly or not. But it’s useful tool.


Rails Webook