On 12 July 2011 02:15, Leigh Daniels <[email protected]> wrote:
> Hi All,
>
> When I enter a Start Date in the text field as "07/11/2011" it gets stored in
> the database as "2011-11-07" instead of "2011-07-11".
>
> This change happens before the column is available in the controller. Is
> there some Rails setting that will make this happen magically or do I have to
> have some fun with date parsing?
If you want to allow the user to enter dates like this you will have
to parse it yourself to make sure the month and day are as you want
them. If the site is for an international audience I suggest you use
separate fields for the three components as otherwise you will have no
end of trouble as most of the world uses day/month/year. I don't
understand what you mean by "it happens before the column is available
in the controller". The field will be passed as a string from the
form to the controller and should appear in params exactly as entered
by the user. Note also that, since you have specified a date field in
the database, what is stored there is not "2011-07-11" or any other
string, but is the date itself.
Colin
>
> Thanks!
>
> **Leigh
>
> ---------------------
>
> [_form.html.erb]
> <%= f.label :start_date, :class => 'label' %><br />
> <%= f.text_field :start_date, :size => 15 %>
>
> [jobs_controller.rb]
> def new
> @job = Job.new
> @job.rate = 125
>
> respond_to do |format|
> format.html # new.html.erb
> format.json { render json: @job }
> end
> end
>
> [schema.rb]
> t.date "start_date"
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.