Hi!
I’m new to Rails, and I have an app which uses text_fields. How can I
set the default value to the current date? I’m using Rails 2.
thanks!
Hi!
I’m new to Rails, and I have an app which uses text_fields. How can I
set the default value to the current date? I’m using Rails 2.
thanks!
Federico Andino wrote:
Hi!
I’m new to Rails, and I have an app which uses text_fields. How can I
set the default value to the current date? I’m using Rails 2.thanks!
Someone told me! I’ve set it into the controller…thanks!
You can set this via the clients browser
<%= Time.now %>
or via a call to the controller (Dry it up)
IE
def index
@current_time = Time.now
end
<%= @current_time %>
in your textfield use the @ current_time method
If you are using 2.0 + their is date_field that allows the setting on
the date/time
IE:
<% form_for(@your_form_object) do |f| %>
Due
<%= f.datetime_select :due %>
<% end %>
PS
using the above form defaults to the current date – be careful of how
this goes into the db
If this info is coming from the db you may want to edit the update
method in the controller so when a item/product is edited/updated
Dooooooo disregard that and read on…
If you have used the default rails migration scripts you should have
two time fields automatically included in your models [tables]
(created_at and updated_at)
as soon as you update/edit the info in this record the updated_at
should reflect the time the date was edited you could use that ??
Sorry about the rant
Hope this helps
On May 13, 10:37 am, Federico Andino <rails-mailing-l…@andreas-
edited you could use that ??
Sorry about the rant
Hope this helpsOn May 13, 10:37 am, Federico Andino <rails-mailing-l…@andreas-
Thanks! I’ll refine the date with this!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs