can we add a string to a instance varaiable....

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........

User.find(:all).group_by(&:month)

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()

   ?

Why? What are you trying to accomplish?

Ryan Bigg wrote:

Why? What are you trying to accomplish?

>

--
Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg

   yeah, 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 ....

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

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)