How to save the date entered from the calendar to the MySQL database

Asked 2 years ago, Updated 2 years ago, 299 views

I have a question.
I want to register the date I selected in the calendar entry in the database, but it doesn't work.
Enter a description of the image here
The key is due_on in params.

I'd like to put it in the column due_on in the reports table on the database, but is the type date correct?Enter a description of the image here

I thought it might be a string type, but could you tell me who knows?

View Code (haml)

=form_with model:@report, html:{class:"Report"}, local:true do | f |
      %ul.Report__contents
        %li = date_field_tag: due_on, Date.today, use_month_number: true
        %li=f.collection_select:job_id,Job.all,:id,:job,include_blank: "Please select content"
        %li=f.collection_select:hour_id,hour.all,:id,:hour,include_blank:"Please select a time"
        %p hours
        %li=f.text_field:impression, class: 'Report__imp', placeholder: 'Improvements'
      = f.submit 'save', class: 'Report__submit'

Controller Code

params.require(:report).permit(:due_on,:job_id,:hour_id,:impression).merge(user_id:current_user.id)

Thank you for your cooperation.

ruby-on-rails

2022-09-30 21:49

1 Answers

Probably
f.date_field
where date_field_tag is set to f.date_field
I think it would be good to go back to
If that doesn't work, please display the full controller statement


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.