[Rails] How to solve the time lag of created_at after save method

[Rails] How to solve the time lag of created_at after save method

For any person

For those who updated the DB with the save method, but the times in the created_at and updated_at columns do not match the current time.

Execution environment

ruby 2.4.10 Rails 5.2.4.3,

Conclusion (cause)

Rails time setting is Greenwich Mean Time You can change it to Japan Standard Time by setting the time zone from config / application.rb.

application.rb


module SampleApp
  class Application < Rails::Application
    config.time_zone = "Tokyo"
  end
end

Rough setting method

① Add time zone setting to application.rb ② Restart the rails console (3) Confirm that the time zone setting is applied by the time.current method.

Specific setting method

① Add time zone setting to application.rb Open config / application.rb and add "config.time_zone =" Tokyo ""

application.rb


module SampleApp
  class Application < Rails::Application
    config.time_zone = "Tokyo"
  end
end

② Start the rails console

$ rails console

(3) Confirm that the time zone setting is applied by the time.current method.

irb(main):003:0> Time.current => Wed, 17 Jun 2020 00:11:56 JST +09:00

Recommended Posts

[Rails] How to solve the time lag of created_at after save method
[Rails] How to use the map method
[Rails] How to omit the display of the character string of the link_to method
How to solve the local environment construction of Ruby on Rails (MAC)!
How to set the display time to Japan time in Rails
[Rails] How to change the column name of the table
[Rails] How to get the contents of strong parameters
[Rails] How to solve the error "undefined method` visit'" when using Capybara with Rspec
Let's summarize how to extend the expiration date of Rails
How to solve the problems of Java's three Blocking Queues
How to use the link_to method
[Ruby On Rails] How to search and save the data of the parent table from the child table
How to use the include? method
How to use the form_with method
[Rails] How to get the URL of the transition source and redirect
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
I tried to understand how the rails method "redirect_to" is defined
[Rails] How to change the page title of the browser for each page
I tried to understand how the rails method "link_to" is defined
How to solve the problem that the website image is not displayed after deploying to heroku on Rails 5
Method definition location Summary of how to check When defined in the project and Rails / Gem
[Rails] How to temporarily save the request URL of a user who is not logged in and return to that URL after logging in
[Java] How to use the toString () method
[Java] How to set the Date time to 00:00:00
How to sort the List of SelectItem
The process of introducing Vuetify to Rails
[Rails] How to use helper method, confimartion
How to decorate the radio button of rails6 form_with (helper) with CSS
How to compare only the time with Rails (from what time to what time, something like)
[Ruby On Rails] How to search the contents of params using include?
How to make the schema of the URL generated by Rails URL helper https
How to implement the email authentication function at the time of user registration
Change the save destination of the image to S3 in the Rails app. Part 2
[Rails] How to decide the destination by "rails routes"
[Order method] Set the order of data in Rails
How to find the cause of the Ruby error
[Ruby on Rails] How to make the link destination part of the specified id
[Rails] Button to return to the top of the page
[Rails] Introduction of pry-rails ~ How to debug binding.pry
Customize how to divide the contents of Recyclerview
Set the time of LocalDateTime to a specific time
How to get today's day of the week
[Rails] How to get rid of flash messages in a certain amount of time
How to use the replace () method (Java Silver)
How to use JQuery in js.erb of Rails6
[Rails] How to operate the helper method used in the main application with Administrate
[Rails] How to solve "Uglifier :: Error: Unexpected character'`'"
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
[Java] How to get the authority of the folder
How to check Rails commands in the terminal
[Rails] How to convert UC time display to Japanese time display
[Ruby basics] How to use the slice method
[Must-see for beginners] I changed the display of the posting time to Japanese time [l method]
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
[rails] After option useful when you want to change the order of DB columns
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
[Rails] How to delete production environment MySQL data after putting it in the development environment
How to use UsageStatsManager in Android Studio (How to check the startup time of other apps)
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
[Java] How to get the URL of the transition source