# Params not working correctly?

**URL:** <https://www.ruby-forum.com/t/params-not-working-correctly/67009>\
**Category:** Rails\
**Created:** [August 30, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/params-not-working-correctly/67009 "2006-08-30T21:43:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [August 30, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/params-not-working-correctly/67009/1 "2006-08-30T21:43:00Z")

</div>

I just did

raise params[:event].inspect

and got

{“change\_mode\_at(1i)”=\>“2006”, “change\_mode\_at(2i)”=\>“8”,  
“change\_mode\_at(3i)”=\>“30”, “change\_mode\_at(4i)”=\>“19”,  
“change\_mode\_at(5i)”=\>“37”, “change\_mode\_to”=\>“0”}

shouldn’t I have a change\_mode\_at with a time object? Because all I get  
is nil.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [August 30, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/params-not-working-correctly/67009/2 "2006-08-30T22:46:38Z")

</div>

Actually no. Rail’s HTML date helper methods puts this little  
paranthesees to group the seperate portions that make up a whole Time  
object. Notice that each of these controls represent parts of your time  
object. So you have a single object that is made up of a year-month-day  
hour:minute:second in your case (2006-8-30 19:37:00), but you can’t just  
use one HTML control to display it all so the framework developers have  
a mismatch between posted params and object layout.

To fix this rails puts those parantheese to distinguish the parts that  
make up the whole. Usually this isn’t an issue unless you’re using  
these controls and splitting your values across multiple fields (i.e. no  
using a standard Time or Date object). Like  
credit\_card[:expiration\_month] and credit\_card[:expiration\_year] and you  
were using the date\_select helper methods. You can work around this  
issue, but this doesn’t sound like what you’re doing.

Check how you’re using the date\_select controls and make sure you have  
the write name of your object’s field. Does your :event object have a  
member called :change\_mode\_at? If not that could be why you’re getting  
nil in the event object you construct.

Charlie

Ben J. wrote:

> I just did
> 
> raise params[:event].inspect
> 
> and got
> 
> {“change\_mode\_at(1i)”=\>“2006”, “change\_mode\_at(2i)”=\>“8”,  
> “change\_mode\_at(3i)”=\>“30”, “change\_mode\_at(4i)”=\>“19”,  
> “change\_mode\_at(5i)”=\>“37”, “change\_mode\_to”=\>“0”}
> 
> shouldn’t I have a change\_mode\_at with a time object? Because all I get  
> is nil.
> 
> Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [August 30, 2006, 10:56pm UTC](https://www.ruby-forum.com/t/params-not-working-correctly/67009/3 "2006-08-30T22:56:10Z")

</div>

Charlie H. wrote:

> Actually no. Rail’s HTML date helper methods puts this little  
> paranthesees to group the seperate portions that make up a whole Time  
> object. Notice that each of these controls represent parts of your time  
> object. So you have a single object that is made up of a year-month-day  
> hour:minute:second in your case (2006-8-30 19:37:00), but you can’t just  
> use one HTML control to display it all so the framework developers have  
> a mismatch between posted params and object layout.
> 
> To fix this rails puts those parantheese to distinguish the parts that  
> make up the whole. Usually this isn’t an issue unless you’re using  
> these controls and splitting your values across multiple fields (i.e. no  
> using a standard Time or Date object). Like  
> credit\_card[:expiration\_month] and credit\_card[:expiration\_year] and you  
> were using the date\_select helper methods. You can work around this  
> issue, but this doesn’t sound like what you’re doing.
> 
> Check how you’re using the date\_select controls and make sure you have  
> the write name of your object’s field. Does your :event object have a  
> member called :change\_mode\_at? If not that could be why you’re getting  
> nil in the event object you construct.
> 
> Charlie.

Yes my events table has a field called change\_mode\_at and it is a  
datetime field. How can I turn this group into a datetime object?

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [August 31, 2006, 1:35am UTC](https://www.ruby-forum.com/t/params-not-working-correctly/67009/4 "2006-08-31T01:35:47Z")

</div>

Ben J. wrote:

> Yes my events table has a field called change\_mode\_at and it is a  
> datetime field. How can I turn this group into a datetime object?

It works with mass assignment but not individual assignment. So this  
won’t work

Event.new(:change\_mode\_at =\> params[:event][:change\_mode\_at])

but this will

Event.new(params[:event])

Active record senses all the components of the date or time fields and  
zips them together.

* * *

This has always bothered me. Wouldn’t it be possible for rails to sense  
this are renconstruct the params so it includes a Time object? Seems  
like that would be much cleaner.
