Search code examples
ruby-on-railsslim-lang

slim gem and Rails 5


Rails 5.1

When I generated the initial application, Rails created some default layouts:

app/views/layouts/application.html.erb
app/views/layouts/mailer.html.erb
app/views/layouts/mailer.text.erb

I would like to use the slim-rails gem. The documentation says all I need to do is include it in the Gemfile, and any views I generate, will be .slim views.

What about the views in the app/views/layouts folder? How do I convert those to .slim?


Solution

  • You do it manually. application.html.erb is just a few lines of code.

    Replace

    <!DOCTYPE html>
    <html>
      <head>
        <title>MyApp</title>
        <%= csrf_meta_tags %>
        <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
        <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
      </head>    
      <body>
        <%= yield %>
      </body>
    </html>
    

    With

    doctype html
    html
      head
        title MyApp
        = csrf_meta_tags
        = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
        = javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
      body
        = yield
    

    And rename the file.

    Same for other files.

    If you have more work to do you could use: