Hi there, Why does the following query... ser = ''ser'' @user = (''U''+ser).find(:first) ...not equal this one: @user = User.find(:first) ? What needs to be done so it will work? Thanks for your help! Tom -- Posted via http://www.ruby-forum.com/.
> > Hi there, > > Why does the following query... > > ser = ''ser'' > @user = (''U''+ser).find(:first) > > ...not equal this one: > > @user = User.find(:first) > > ? > > What needs to be done so it will work?>> ser = ''ser'' => "ser" >> user = ''U'' + ser => "User" >> user.class => String >> User.class => Class >> user.constantize.class => Class >> user.constantize.find(:first) User Load (1.2ms) SELECT * FROM "users" LIMIT 1 => #<User id: 1,.........
Great - thanks! -- Posted via http://www.ruby-forum.com/.
which can get you to some cool code like: @object = params[:controller].singularize.camelcase.constantize.find(params[:id]) -- Posted via http://www.ruby-forum.com/.
1 question back, though: What if need to end up having... @user = User.find(:first) ...based on a case like this: @u = ''@u'' ser = ''ser'' Is there something as "objectize"? :-) How would the following need to be corrected? (@u+ser).objectize = User.find(:first) Thanks for your help! Tom -- Posted via http://www.ruby-forum.com/.
instance_variable_set(@u + ser, User.find(:first)) On May 15, 1:27 pm, Tom Ha <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 1 question back, though: > > What if need to end up having... > > @user = User.find(:first) > > ...based on a case like this: > > @u = ''@u'' > ser = ''ser'' > > Is there something as "objectize"? :-) > > How would the following need to be corrected? > > (@u+ser).objectize = User.find(:first) > > Thanks for your help! > Tom > -- > Posted viahttp://www.ruby-forum.com/.