# Params element find problem

**URL:** <https://www.ruby-forum.com/t/params-element-find-problem/73290>\
**Category:** Rails\
**Created:** [October 23, 2006, 4:25pm UTC](https://www.ruby-forum.com/t/params-element-find-problem/73290 "2006-10-23T16:25:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [October 23, 2006, 4:25pm UTC](https://www.ruby-forum.com/t/params-element-find-problem/73290/1 "2006-10-23T16:25:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [October 23, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/params-element-find-problem/73290/2 "2006-10-23T16:37:22Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [October 23, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/params-element-find-problem/73290/3 "2006-10-23T16:48:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [October 23, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/params-element-find-problem/73290/4 "2006-10-23T16:58:53Z")

</div>

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/](http://www.ruby-forum.com/).

This might be helpful…

[http://codefluency.com/2006/7/13/rails-views-preprocessing-parameters](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
