Jarek Plonski
2011-Aug-06 18:20 UTC
Accessing datetime elements from hash passed to method
I''m passing hash (called ''params'') to a method. Some keys (one of them is called ''starts_at'') in that hash have date as a value (taken from datetime_select helper). I want to access the date elements like date only or time only but I''m just out of ideas. def self.new_meeting(params) str = params[''starts_at(1i)''] puts str end This returns nothing. def self.new_meeting(params) str = params[:starts_at] puts str end This returns whole date with time. Ruby 1.9.2 Rails 3.0.7 Can you help a newbie?? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Aug-06 19:10 UTC
Re: Accessing datetime elements from hash passed to method
On Aug 6, 7:20 pm, Jarek Plonski <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m passing hash (called ''params'') to a method. Some keys (one of them > is called ''starts_at'') in that hash have date as a value (taken from > datetime_select helper). I want to access the date elements like date > only or time only but I''m just out of ideas. > > def self.new_meeting(params) > str = params[''starts_at(1i)''] > puts str > end > > This returns nothing. > > def self.new_meeting(params) > str = params[:starts_at] > puts str > end > > This returns whole date with time. > > Ruby 1.9.2 > Rails 3.0.7 > > Can you help a newbie?? >Time/date objects have methods like year, month, day etc. which return the individual components Fred> -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jarek Plonski
2011-Aug-06 19:50 UTC
Re: Accessing datetime elements from hash passed to method
> Time/date objects have methods like year, month, day etc. which return > the individual components >Well I know that but, can you, please, tell how to use those methods in my example? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Aug-06 20:04 UTC
Re: Re: Accessing datetime elements from hash passed to method
On 6 August 2011 20:50, Jarek Plonski <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> Time/date objects have methods like year, month, day etc. which return >> the individual components >> > > Well I know that but, can you, please, tell how to use those methods in > my example?I don''t know the format of you params string but you can probably use something like starts_at = Time.parse( params[:starts_at] ) puts starts_at.year Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jarek Plonski
2011-Aug-06 20:20 UTC
Re: Re: Accessing datetime elements from hash passed to method
> starts_at = Time.parse( params[:starts_at] ) > puts starts_at.yearColin, this is exactly what I needed. Thank you! :) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud --
2011-Aug-06 20:46 UTC
Re: Re: Accessing datetime elements from hash passed to method
Jarek Plonski wrote in post #1015315:>> starts_at = Time.parse( params[:starts_at] ) >> puts starts_at.year > > Colin, this is exactly what I needed. Thank you! :) >Well, you lied. You didn''t have a Date, you had a String. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jarek Plonski
2011-Aug-06 21:57 UTC
Re: Re: Accessing datetime elements from hash passed to method
> Well, you lied. You didn''t have a Date, you had a String.I''m not saying that I know what I''m talking about :) I''m newbie but I didn''t lie. What I said was: "...date as a value (taken from datetime_select helper)" if it was a String then datetime_select returns a string, or Dates are Strings but with some order. I''m getting confused now. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Aug-07 07:01 UTC
Re: Re: Re: Accessing datetime elements from hash passed to method
On 6 August 2011 22:57, Jarek Plonski <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> Well, you lied. You didn''t have a Date, you had a String. > > I''m not saying that I know what I''m talking about :) > > I''m newbie but I didn''t lie. > > What I said was: > "...date as a value (taken from > datetime_select helper)" > > if it was a String then datetime_select returns a string, or Dates are > Strings but with some order. > > I''m getting confused now.I think values in params hash are always strings as they are just the strings taken from the http request. As you said, you never said that you had a Date object. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.