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!