HI , can we add a string to an instance variable like @jan+"#{users}"=User.find(:all) because i''ve the same query to be executed for both User and Post, for every month jan..dec. so can i write a method which contains @jan+"#{name}"=#{Name}.find(:all) name--> either post or user that i pass to the method.... and how to convert Name i,e; string into object? plz reply........ -- 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg (Radar)
2008-Jun-16 06:41 UTC
Re: can we add a string to a instance varaiable....
User.find(:all).group_by(&:month) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> User.find(:all).group_by(&:month)i need some thing like @jan is an instance varaible and can i add a string like name="hi" to the instance variable like @jan+"#{name}" is it possible and even i want to know can we convert a string object into object(instance)? like we do in java to_String() and to_Object() ? -- 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg (Radar)
2008-Jun-16 07:06 UTC
Re: can we add a string to a instance varaiable....
Why? What are you trying to accomplish? On Mon, Jun 16, 2008 at 4:30 PM, Vamsi Krishna < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ryan Bigg wrote: > > User.find(:all).group_by(&:month) > > i need some thing like > > @jan is an instance varaible and can i add a string like name="hi" > to the instance variable like > > @jan+"#{name}" > > is it possible and even i want to know can we convert a string object > into object(instance)? > > > like we do in java to_String() and to_Object() > > ? > -- > Posted via http://www.ruby-forum.com/. > > > >-- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Why? What are you trying to accomplish? > > On Mon, Jun 16, 2008 at 4:30 PM, Vamsi Krishna < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> > >> > > > -- > Appreciated my help? > Recommend me on Working With Rails > http://workingwithrails.com/person/11030-ryan-biggyeah, to be clear ..... i''ve 2 methods one for posts and another for users... i''d like to get number of users for every month and same for number of posts for every month.. for that i had written like @januser=User.find(:all,:condition=>["created_at between ? AND ?","#{changedyear}-01-01","#{changedyear}-01-31"]) like this for every month as i don''t ''ve a feild name month in database.... and the same query can be used by post like @janpost=Post.find(:all,:condition=>["created_at between ? AND ?","#{changedyear}-01-01","#{changedyear}-01-31"]) and changedyear is a dynamic one........... so the query is same for both of them... so can i write @jan+"#{name}"="#{Name}".find(:all,:condition=>["created_at between ? AND ?","#{changedyear}-01-01","#{changedyear}-01-31"]) where name may be post or user .... -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-16 07:49 UTC
Re: can we add a string to a instance varaiable....
On Jun 16, 8:31 am, Vamsi Krishna <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> so the query is same for both of them... > > so can i write > > @jan+"#{name}"="#{Name}".find(:all,:condition=>["created_at between ? > AND ?","#{changedyear}-01-01","#{changedyear}-01-31"]) where name may be > post or user ....Well I thin you''re looking for instance_variable_set and constantize, but personally I''d put most of that method in the post/user model (and probably return a hash keyed by the month you''re looking at). Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg (Radar)
2008-Jun-16 07:58 UTC
Re: can we add a string to a instance varaiable....
The finder methods generated by ActiveRecord take a range (I think), so you can find the start date for January and then the end date and do something like this: Post.find_all_by_created_at(beginning_of_january..end_of_january) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---