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
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
@user = User.find(:first)
?
What needs to be done so it will work?
ser = ‘ser’
=> “ser”user = ‘U’ + ser
=> “User”user.class
=> StringUser.class
=> Classuser.constantize.class
=> Classuser.constantize.find(:first)
User Load (1.2ms) SELECT * FROM “users” LIMIT 1
=> #<User id: 1,…
Great - thanks!
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
instance_variable_set(@u + ser, User.find(:first))
which can get you to some cool code like:
@object =
params[:controller].singularize.camelcase.constantize.find(params[:id])
Thanks!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs