Rails new in Ruby on Rails ~ Memorandum until deployment 2

It is a memorandum 2 from Rails new to deployment in Ruby on Rails!

, Rails new command will write a series from application creation to deployment.

Last time https://qiita.com/gonshiba-n/items/abd1b11e35f99eb5975f

Japanese localization of Rails application and adaptation to Japan time

config/application.rb


require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module xxxxxx
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
#from here
    config.time_zone = 'Asia/Tokyo' #Japan time setting
    config.i18n.default_locale = :ja #Japanese setting
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] #Ja at startup.Have yml read
#Add up to here
#-abridgement-
  end
end

Now that you have set the Japanese localization, let's get the file to read! Is the terminal now in the Rails working directory? If so, enter the following command to get the Japanese localization file from GitHub.

Terminal.


curl -s https://raw.githubusercontent.com/svenfuchs/rails-i18n/master/rails/locale/ja.yml -o config/locales/ja.yml

Next is Japan time. Create a new time_formats.rb in the initializers directory inside the config directory.

Terminal.


touch config/initializers/time_formats.rb

Now you can create it! Open time_formats.rb and write the code below and you're ready to go.

config/initializers/time_formats.rb


Time::DATE_FORMATS[:datetime_jp] = '%Y year%m month%d day%H o'clock%M minutes'

Actually, by using it as follows It will be displayed like 12:00 on September 25, 2020.

<%= xxxxx.created_at.to_s(:datetime_jp) %>
<%= xxxxx.updated_at.to_s(:datetime_jp) %>

I've summarized the introduction of Rspec in the past, so please check it out! https://qiita.com/gonshiba-n/items/36c91e000fdc9b18aa28 However, if you write Rspec in the development environment and the test environment, you can use the generator that creates the test file, so it seems better to put it in the group below!

I will also add Rubocop. Rubocop is called a linter, and it's a great way to check if your code is out of the rules or if you have a typo!

Gemfile.


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
#Here are the test gems including Rspec
  gem 'rspec-rails'
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  gem 'webdrivers'
  gem 'factory_bot_rails'
  gem 'rubocop-airbnb'#← Linter
end

If you write another gem you want to use

Terminal.


bundle

Do the above!

For more information on Rubocop, please refer to this article! https://qiita.com/shunsuke_sasauchi/items/70ccc4b02be72640f699

root settings

Set the page that is displayed first when you access the rails app. Right now, it's just a template and nothing is inside, so I'll create it. Let's make various things such as View and controller with rails g controller.

Terminal.


rails g controller StaticPages top about login

Sorry for my example! With this, rails created this and that automatically.

Next, set the ruding. Open config / routes.rb!

config/routes.rb


Rails.application.routes.draw do
  resources :static_pages#← This is leaving the resource to erase the code created by rails

  root 'static_pages#top'#← Add this
end

This completes root setting! Start the server as a trial http://localhost:3000 If you access and look at, you will see the page you set.

Settings in config / environments / production.rb

In the production environment, the dynamic display of the image is off, so change it to on!

config/environments/production.rb


  config.assets.compile = true #False by default
end

This is OK!

Finally deploy to heroku!

Please register on heroku! I think I needed a credit card, but if you search for it, I think there is an insanely easy-to-understand article, so please refer to that! Since I am using PostgreSQL, I have not made any settings around the DB. Please note that if you use another DB, you will need to set it separately.

First, let's log in after making heroku available with the CLI!

Terminal.


heroku login

I will create an application on heroku. Since the app name is incorporated into the URL as it is, characters that cannot be used in the URL cannot be used! And you can't use the app name that has already been used!

Terminal.


heroku create favorite app name(To be used in URLs_I can't use)

Finally, push and deploy to heroku's remote repository.

Terminal.


git push heroku master

If you have a DB migration file, please migrate it with the following command.

Terminal.


heroku run rails db:migrate

At this point, let's actually access the URL and check it!

Finally

Thank you for reading this far. Last time, I deployed it just before the application was completed, so I had a lot of trouble. It's definitely easier to deploy after setting up the application before development, I think that the sense of security that you can develop while checking the operation in both the development environment and the production environment is tremendous. So far, I've written only the procedure, but I can't! I got an error! Or something wrong! In that case, I would appreciate it if you could teach me.

Recommended Posts

Rails new in Ruby on Rails ~ Memorandum until deployment 2
Rails new in Ruby on Rails ~ Memorandum until deployment 1
Ruby on Rails Basic Memorandum
Ruby on Rails Japanese-English support i18n
[Ruby on Rails] Stop "looping until ..."
Ruby on Rails in Visual Studio Codespaces
Ruby on Rails application new creation command
Beginners create portfolio in Ruby on Rails
I summarized the flow until implementing simple_calendar in Ruby on Rails.
Change from SQLite3 to PostgreSQL in a new Ruby on Rails project
[Ruby on Rails] Until the introduction of RSpec
Recommendation of Service class in Ruby on Rails
Ruby on Rails Elementary
[Ruby on Rails] A memorandum of layout templates
Ruby on Rails basics
(Ruby on Rails6) Creating data in a table
Ruby On Rails Association
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] How to write enum in Japanese
[Ruby on Rails Tutorial] Error in the test in Chapter 3
[Ruby On Rails] How to reset DB in Heroku
[Ruby on Rails] Post image preview function in refile
Ruby on rails learning record -2020.10.03
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Definitely useful! Debug code for development in Ruby on Rails
Ruby on Rails for beginners! !! Summary of new posting functions
[Ruby on Rails] Quickly display the page title in the browser
[Apple login] Sign in with Apple implementation procedure (Ruby on Rails)
How to display a graph in Ruby on Rails (LazyHighChart)
Apply CSS to a specific View in Ruby on Rails
[Ruby on Rails] Read try (: [],: key)
[Ruby on Rails] yarn install --check-files
Ruby on Rails variable, constant summary
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
Basic knowledge of Ruby on Rails
Progate Ruby on Rails5 Looking Back
How to use Ruby on Rails
[Ruby on Rails] Add / Remove Columns
Create a new app in Rails
(Ruby on Rails6) "Erase" posted content
[Ruby on Rails] CSV output function
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] What is Bcrypt?
Launch Rails on EC2 (manual deployment)
[Ruby on Rails] Confirmation page creation
[Today's stack # 1] Until on rails on cloud9
Ruby On Rails devise routing conflict