Sri
Sri

Reputation: 2273

How to use the date_select and time_select in the form in rails?

I have a Date and Time column separately in the table in my database. When i click the Edit in the table, the Date and Time should display the values by params. The User can change the Date and the Time and update the form.

I tried the following:

<div class="field">
  <%= f.label :Sent_Date, 'Sent Date:' %>
  <%= date_select(:Appointment_Date, object: f.object) %>
</div>

<div class="field">
  <%= f.label :Appointment_Time, 'Appointment Time:' %>
  <%= f.time_select(:history, :Appointment_Time, include_seconds: true) %>
</div>

It's not display the values correctly and it doesn't change to next record. It display to select the value. Do I need to convert the date here? Because, In the Database, its just the value like 2013/05/13 and in the field its like 20 December 2013

Time field is not working. Please suggest me how to get solve this issue.

Thanks

Upvotes: 0

Views: 521

Answers (1)

Dennis Hackethal
Dennis Hackethal

Reputation: 14275

Don't use constants as fields for your model. Any variable starting with a capital letter will be treated like a constant, and constants are meant not to change. Ruby will give you a warning: already initialized constant when trying to change a constant's value, so that might be the reason you can't change the time and date.

Upvotes: 1

Related Questions