What to do when you launch an application with rails

Introduction

This is a post for the output of "Ruby on Rails 5 Quick Learning Practice Guide". Since I use rails for business, I am trying to accumulate knowledge even in private. This time, I will post the settings related after launching the application of this book.

table of contents

  1. Convert to slim file (#Chapter2)
  2. Install bootstrap
  3. Convert to scss file (#Chapter4)
  4. Japanese localization of error message
  5. Japaneseize model column name
  6. References

Convert to slim file

Added the following to the last line of Gemfiile

gem 'slim-rails'
gem 'html2slim'

After writing, execute the following in the terminal

bundle install
bundle exec erb2slim app/views/layouts/ -d

The command on the second line creates a slim file based on erb from the files under "app/views/layouts /". The option "-d" is an option to delete the html file. If you want to keep the html file, do not add this option.

Introducing bootstrap

Added the following to the last line of Gemfiile

gem 'bootstrap'

After writing, execute the following in the terminal

bundle install

Convert to scss file

Delete app/assets/stylesheets/application.css, create application.scss in the same folder, and add the following description to the file.

app/assets/stylesheets/application.scss


@import 'bootstrap'

Japanese localization of error messages

There is a translation in the rails-I18n repository on GitHub, so download it with the following command.

wget https://raw.githubusercontent.com/svenfuchs/rails-i18n/master/rails/locale/fa.yml -P config/locales/

After downloading, create locale.rb so that Japanese content is used by default, and add the following description.

config/initializers/locale.rb


Rails.application.config.i18n.default_locale = :ja

Japanese localization of model column names

When the model name is displayed on the screen, the column name of the table is output as it is. (Example: When it is User.name, it will be displayed as name) Therefore, assign Japanese corresponding to the model name and column name to ja.yml. Please note that if the indentation shifts, it will not work!

config/locales/ja.yml


---
ja:
  activerecord:
    errors:
      messages:
        record_invalid: 'Validation failed: %{errors}'
        restrict_dependent_destroy:
          has_one: "%{record}Cannot be deleted because it exists"
          has_many: "%{record}Cannot be deleted because it exists"
    models:
      task:task
    attributes:
      task:
        id: ID
        name:name
        description:detailed explanation
        created_at:Registered Date
        updated_at:Update date and time

After definition, use the human_attribute_name method in the view to display in Japanese.

Task.human_attribute_name(:name)

In this description, it is displayed as "Name".

References

-Ruby on Rails 5 Quick Learning Practice Guide that can be used in the field

Recommended Posts

What to do when you launch an application with rails
What to do if ffi installation fails when launching an application in Rails
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
[Rails] What to do if you can't get parameters with form_with
[Rails] What to do if you can't get an error message with the errors method
What do you use when converting to String?
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you get an error when you hit Heroku logs
What to do when rails creates a 〇〇 2.rb file
An introductory book to read when you start Rails
What to do if you get Application with name appName is already registered. When you try to start GlassFish
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get an "A server is already running." Error when you try to start the rails server
# What to do if you accidentally do rails db: migrate: drop
How to specify db when creating an app with rails
What happens to instance variables when copying an instance with ruby
What to do when javax.batch.operations.JobStartException occurs
What to do if you can't use the rails command
[Rails] What to do when you want to generate an error that cannot be destory when foreign key restrictions are applied
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
[Rails] What to do when the view collapses when a message is displayed with the errors method
What to do if you get an error in Basic authentication during Rails test code
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What I was addicted to when implementing google authentication with rails
[Rails] What to do when rails s does not respond or does not stop
What to do if you get angry with OpenSSL with pyenv install
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do when a javax.el.PropertyNotWritableException occurs
What to do if you install Ubuntu
What to do when undefined method ʻuser_signed_in?'
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
What to do if the app is not created with the latest Rails version installed when rails new
[IOS] What to do when the image is filled with one color
What to do when CentOS cannot be started with VirtualBox on Catalina
What to do if you get an uninitialized constant Likes Controller error
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if an error occurs when nokogiri enters when bundle install
Notes on what to do when EC2 is set up with t2.micro
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
Downgrade an existing app created with rails 5.2.4 to 5.1.6
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if you push incorrect information
What to do if zip dies if there is a pom when making an executable jar with gradle
What to do when debugging "Source not found"
[Rails] How to build an environment with Docker
What to do when IllegalStateException occurs in PlayFramework
What to do when you want to delete a migration file that is "NO FILE"
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What to do when rails db: seed does not reflect in the database
What to do if you get an error on heroku rake db: migrate
What to do when is invalid because it does not start with a'-'
WELD-001408: What to do when Unsatisfied dependencies for type Bean with qualifiers @Default
[Rails] Create an application
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What to do if the Rails server can't start
What to do when The SSL certificate has expired
What to do when JSF tags do not become HTML