What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field

Error occurred

When I implemented the post form in Rails, it worked fine on my PC,

For some reason, when I tried to use it on my smartphone, there was a part where an error occurred, so I will write it down.

ruby:new.html.erb


<%= form_for @ride, method: :post do |f| %>
    <h1>Post a new ride!</h1>
    <label>title</label>
    <p><%= f.text_field :title %></p>
    <label>scheduled date</label>
    <br />
    <%= f.datetime_field :sch_datetime %><br />
    <br />
    <input class="btn btn-primary" type="submit" value="Post">
  <% end %>

config/initializers/time_formats.rb


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

config/locales/application.rb


class Application < Rails::Application
    config.load_defaults 5.2
    config.i18n.default_locale = :ja
    config.assets.paths << config.root.join("vendor/assets/javascripts")
    config.assets.paths << config.root.join("vendor/assets/stylesheets/")
    config.action_view.embed_authenticity_token_in_remote_forms = true
    config.time_zone = 'Tokyo'
end

The first thing I wrote was like this, by using datetime_field, I was able to get the date and time all at once.

I confirmed that it works on the PC with this method without any problems, so I deployed it in this state, but

Suddenly I tried to check the operation on my smartphone, and when I tried to post it, the date and time part

** I got an error saying "Please enter a valid value" and could not post. .. .. **

What is the cause?

I thought, but I guessed that it was not a code mistake because it works normally on the PC.

Since the form when inputting on the smartphone and PC has also changed, there seems to be a problem with datetime_field itself ~

I thought, so I decided to write it separately for date_field and time_field.

ruby:new.html.erb


<%= form_for @ride, method: :post do |f| %>
    <h1>Post a new ride!</h1>
    <label>title</label>
    <p><%= f.text_field :title %></p>
    <label>scheduled date</label>
    <br />
    #from here
    <%= f.date_field :sch_datetime %><br />
    <br />
    <%= f.time_field :sch_datetime %><br />
  #Change so far
    <br />
    <input class="btn btn-primary" type="submit" value="Post">
  <% end %>

When I checked the operation in this state, it worked without any problem!

Recommended Posts

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 saying "Could not find a JavaScript runtime." When starting rails server
What to do if you get an "A server is already running." Error when you try to start the rails server
[Rails] What to do if you can't get an error message with the errors method
What to do if you get an error during rails db: reset
What to do if you get an error when you hit Heroku logs
[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 when you launch an application with rails
What to do if you get a port error when docker-compose up on Mac
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
[Rails] What to do if you can't get parameters with form_with
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get an error in Basic authentication during Rails test code
What to do if you get an error saying Cannot find a valid baseurl for repo when you use yum -y install docker in a udemy course using CentOS7
What to do if you get an uninitialized constant Likes Controller error
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get a JNI shared library error when trying to build in Eclipse
<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 you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get an error on heroku rake db: migrate
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you get the error Couldn't find Item without an ID
What to do if you get a java.io.IOException in GlassFish
[Java] What to do if you get an error in Eclipse saying "Not allowed at source level below 1.X"
What to do if you get angry with OpenSSL with pyenv install
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if you get a groovy warning in Thymeleaf Layout
What to do if an error occurs when nokogiri enters when bundle install
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if zip dies if there is a pom when making an executable jar with gradle
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
What to do if you get the error message unrecognized selector send to instance "***"
What to do if ffi installation fails when launching an application in Rails
What to do if you accidentally create a model
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
What to do if you can't get the text of an element in Selenium
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
[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 accidentally do rails db: migrate: drop
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
[Rails] What to do when the view collapses when a message is displayed with the errors method
[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]
How to make a jar with old Hadoop (hadoop-core-0.20.2-cdh3u6) in Gradle: (What to do if you get Could not expand ZIP ..)
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
[Programming beginner] What to do when rails s becomes an error in the local development environment
I get a Ruby version error when I try to start Rails.
What to do if an SSH key authentication error occurs during automatic deployment to EC2 with Capistrano
What to do when you become a Problem During Content Assist
What to do if the app is not created with the latest Rails version installed when rails new
What to do when you run into a docker-compose node_modules problem
What to do if you get "Changes not staged for commit:" when you git status after git add.
What to do if an error occurs when doing npm install axios in React + Typescript project