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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> <%= 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 Man <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/16/07, Walde Man <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Robert Walker 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 <tt>params={:meetup=>{:"time(1i)=>..."}}</tt> just do # following: # # <tt>Time.parse_from_attributes(params[:meetup], :time)</tt> 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 Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On May 16, 2:56 pm, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/16/07, Walde Man <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > Robert Walker wrote: > > > > Sorry, I don''t know if Rails supplies a convenient way to parse this > > > into aDateobject 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 <tt>params={:meetup=>{:"time(1i)=>..."}}</tt> just do > # following: > # > # <tt>Time.parse_from_attributes(params[:meetup], :time)</tt> > 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 Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---