STRFTIME() why is it not defined

I am trying to take the input from a field in wich the user enters a
date, and formatting it to my time format
if params[:gotcha] != ‘’
gotc = params[:date].to_a
gotc.strftime("%m/%d/%y")
end
Yet I get this error:
NoMethodError in AddController#add

undefined method `strftimeâ?? for [“00000”]
What’s wrong. I’m positive this method is defined. What’s wrong with my
code? It’s so odd… Thanks for your help and time.

Ben V. wrote:

I am trying to take the input from a field in wich the user enters a
date, and formatting it to my time format
if params[:gotcha] != ‘’
gotc = params[:date].to_a
gotc.strftime("%m/%d/%y")
end
Yet I get this error:
NoMethodError in AddController#add

undefined method `strftimeâ?? for [“00000”]
What’s wrong. I’m positive this method is defined. What’s wrong with my
code? It’s so odd… Thanks for your help and time.

EDIT: it should not be .to_a. I removed that in a later version of the
code

Ben V. wrote:

Ben V. wrote:

I am trying to take the input from a field in wich the user enters a
date, and formatting it to my time format
if params[:gotcha] != ‘’
gotc = params[:date].to_a
gotc.strftime("%m/%d/%y")
end
Yet I get this error:
NoMethodError in AddController#add

undefined method `strftimeâ?? for [“00000”]
What’s wrong. I’m positive this method is defined. What’s wrong with my
code? It’s so odd… Thanks for your help and time.

EDIT: it should not be .to_a. I removed that in a later version of the
code

I wish it would be possible to edit topics after they are posted, but
unfortunatel y not. I forgot to mention that despite try to_a, to_s etc.
and plain (no to_vartype) It is still not solved. Sorry for all the
posts.

It’s failing because ‘gotc’ is a String, and strftime works on date
objects.

Ok, so i tried this:
gotc = params[:date].to_d
gotc.strftime("%m/%d/%y")
but now it’s saying that to_d doesn’t exist. If it helps, I’m using this
within a controller. What would I do to succesfully convert to a date
object and strftime() it?

Ben V. wrote:

It’s failing because ‘gotc’ is a String, and strftime works on date
objects.

Ok, so i tried this:
gotc = params[:date].to_d
gotc.strftime(“%m/%d/%y”)

but now it’s saying that to_d doesn’t exist.

If it helps, I’m using this

within a controller. What would I do to succesfully convert to a date
object and strftime() it?

ActiveSupport allows you to use gotc.to_date

Hope it helps :]

[email protected]
Gustav
itsdEx.com

On Friday, July 28, 2006, at 5:07 AM, Ben V. wrote:

What’s wrong. I’m positive this method is defined. What’s wrong with my
code? It’s so odd… Thanks for your help and time.


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

It’s failing because ‘gotc’ is a String, and strftime works on date
objects.

_Kevin
www.sciwerks.com

ActiveSupport allows you to use gotc.to_date

Hope it helps :]

Of course, how could I miss that; I thought it was to_d, but I guess the
syntax is different for dates than it is strings and arrays. Thanks for
your help. It’s working properly know. I’m new to Ruby/Rails from
Coldfusion, and while the code is much more beautiful and easy, I don’t
like that specific functions are restricted to certain datatypes and
specfic parts of the application wheras in CF if it is in the manual you
can use it prety much wherever, but overall, despite CF also being a
pretty easy language, I have found Ruby to be much faster.
Thanks,
Ben