# How I can use date from form via params?

**URL:** <https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247>\
**Category:** Rails\
**Created:** [May 15, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247 "2007-05-15T22:29:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alabama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@alabama](https://www.ruby-forum.com/u/alabama)\
**Post date:** [May 15, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247/1 "2007-05-15T22:29:08Z")

</div>

Hi everybody !  
Is somebody so polite and tell me, how I can use date from form via  
params ?  
For egzample:  
I have form “customer”.  
When I have to use in my controller customer name, I can write :  
@name = params[:customer][:name]  
But I haven’t idea how I can write date like “birthday”, which is in  
form as  
\<%= date\_select(:customer, :birthday) %\>  
When I wrote in controller:  
@birthday = params[:customer][:birthday]  
it doesn’t work.  
Date is divide in params on tree parts like birthday(1i), birthday(2i)  
birthday(3i) but I don’t know what is proper format to use it via  
params.

---

<div class="post-metadata">

**Author:** ![alabama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@alabama](https://www.ruby-forum.com/u/alabama)\
**Post date:** [May 16, 2007, 2:38pm UTC](https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247/2 "2007-05-16T14:38:29Z")

</div>

Robert W. wrote:

> Sorry, I don’t know if Rails supplies a convenient way to parse this  
> into a Date object individually. But, it likely has something for  
> that.

Thanks for your endeavor, Robert.

Because I wasn’t operated on ActiveRecord model, I used another helper  
-\> “select\_date” with option “:prefix” in order to distinguish more than  
one date. Then, it wasn’t so difficult parse date via params.

Best regards, Walde.

---

<div class="post-metadata">

**Author:** ![alabama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@alabama](https://www.ruby-forum.com/u/alabama)\
**Post date:** [May 15, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247/3 "2007-05-15T23:09:53Z")

</div>

> \<%= date\_select(:customer, :birthday) %\>

As far as I understand it Rails is expecting :customer to be an  
ActiveRecord subclass and :birthday to be an attribute of Customer.  
When using params[:customer] in your controller for “mass assignment”  
it will take care of setting my\_customer.birthday automatically for  
you.

Sorry, I don’t know if Rails supplies a convenient way to parse this  
into a Date object individually. But, it likely has something for  
that.

On May 15, 4:29 pm, Walde M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![alabama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@alabama](https://www.ruby-forum.com/u/alabama)\
**Post date:** [June 19, 2007, 12:11am UTC](https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247/4 "2007-06-19T00:11:00Z")

</div>

Hi,

I have exactly the same problem. I am using a form separated from any  
model, and I use a date object. Then I send by mail the information  
contained in this form.  
However when I access to my date object in the template for the mail I  
have a string looking like “(3i)2(1i)2007(2i)1(1i)  
(3i)2(1i)2007(2i)1(2i)(3i)2(1i)2007(2i)1(3i)”.

I think the previous answer is what I am looking for but I can get it  
to work, the method is not found…

Any help or suggestion to work over this?

Thanks  
Chewbie

---

<div class="post-metadata">

**Author:** ![alabama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@alabama](https://www.ruby-forum.com/u/alabama)\
**Post date:** [May 16, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/how-i-can-use-date-from-form-via-params/104247/5 "2007-05-16T21:57:15Z")

</div>

On 5/16/07, Walde M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Robert W. wrote:
> 
> > Sorry, I don’t know if Rails supplies a convenient way to parse this  
> > into a Date object individually. But, it likely has something for  
> > that.

class Time  
class \<\< self  
# Used for getting multifield attributes like those generated by a  
# select\_datetime into a new Time object. For example if you have  
# following params={:meetup=\>{:“time(1i)=\>…”}} just do  
# following:  
#  
# Time.parse\_from\_attributes(params[:meetup], :time)  
def parse\_from\_attributes(attrs, field, method=:gm)  
attrs = attrs.keys.sort.grep(/^#{field.to\_s}(.+)$/).map { |k|  
attrs[k] }  
attrs.any? ? Time.send(method, \*attrs) : nil  
end  
end  
end

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
