params element find problem

Sam Woodard wrote:

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?


Posted via

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.


Sam Woodard 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

This might be helpful...

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