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.
config/application.rb
module App
class Application < Rails::Application
config.generators.template_engine = :slim #Change to slim
end
end
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.
views/tweets/index.html.slim
Hello, world!
Add an index action inside the controller.
controllers/tweets_controller.rb
class ArchivesController < ApplicationController
def index
end
end
Next is routing.
config/routes.rb
Rails.application.routes.draw do
root "tweets#index"
end
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".
http://localhost:3000/
Recommended Posts