Params element find problem

I call admin/2006 and routes.rb sends 2006 as param[:year] to admin/list
(controller/action). List then uses Day.find_by_year( params[:year] )
to find all Day records for that particular year. However, it is
passing find_by_year ‘2006’ instead of 2006 and sql is throwing an error
because it is getting,

WHERE (date >= ‘‘2006’-01-01’ AND date <= ‘‘2006’-12-31’)

instead of

WHERE (date >= ‘2006-01-01’ AND date <= ‘2006-12-31’)

.

How do I fix it so that the routing does not put ‘2006’ in
params[:year], but rather, just 2006?

Sam

Sam W. wrote:

WHERE (date >= ‘2006-01-01’ AND date <= ‘2006-12-31’)

.

How do I fix it so that the routing does not put ‘2006’ in
params[:year], but rather, just 2006?

Sam


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

All parameters get serialized as strings, so what you really need to do
is modify your line to read something like this…

Day.find_by_year( params[:year].to_i)

This just forces the string representation of year to an integer.

_Kevin

Is there anyway to store the year as an integer into params[:year]
instead of a string? It does this for the default route param, :id.

Sam W. wrote:

Is there anyway to store the year as an integer into params[:year]
instead of a string? It does this for the default route param, :id.


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

This might be helpful…

http://codefluency.com/2006/7/13/rails-views-preprocessing-parameters

BTW, on my system the raw params hash sends the :id as a string.

_Kevin