Hi all, Is it possible to pass a model name as a variable? For example in controller there is a method like this, def list var = User.find(:all) end where in var we heve collected all data from users table. If i edit the above code like the one below, will it do the same work? def list(modl) var = tab.find(:all) end def hi tab = User list(tab) end someone please help. thanks, shanmu -- 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 -~----------~----~----~----~------~----~------~--~---
Andrew Timberlake
2009-Jan-21 07:39 UTC
Re: Is it possible to pass a model name as a variable?
Yes it will but you have a bug in your code, it should be: def list(modl) On Wed, Jan 21, 2009 at 9:14 AM, Shanmu Gam < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi all, > Is it possible to pass a model name as a variable? > For example in controller there is a method like this, > > def list > var = User.find(:all) > end > > where in var we heve collected all data from users table. If i edit the > above code like the one below, will it do the same work? > > > def list(modl) > var = tab.find(:all) > end > > def hi > tab = User > list(tab) > end > > someone please help. > > thanks, > shanmu > -- > Posted via http://www.ruby-forum.com/. > > > >-- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Timberlake
2009-Jan-21 07:41 UTC
Re: Is it possible to pass a model name as a variable?
On Wed, Jan 21, 2009 at 9:14 AM, Shanmu Gam < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi all, > Is it possible to pass a model name as a variable? > For example in controller there is a method like this, > > def list > var = User.find(:all) > end > > where in var we heve collected all data from users table. If i edit the > above code like the one below, will it do the same work? > > > def list(modl) > var = tab.find(:all) > end > > def hi > tab = User > list(tab) > end > > someone please help. > > thanks, > shanmu > -- > Posted via http://www.ruby-forum.com/. > > > >Yes it will but you have a bug in your code, it should be: def list(modl) var = modl.find(:all) #Must call find on modl, not tab end def hi tab = User list(tab) end Can be simplified as: def list(modl) modl.find(:all) end def hi list(User) end -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Timberlake wrote:> On Wed, Jan 21, 2009 at 9:14 AM, Shanmu Gam < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> above code like the one below, will it do the same work? >> >> someone please help. >> >> thanks, >> shanmu >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > Yes it will but you have a bug in your code, it should be: > > def list(modl) > var = modl.find(:all) #Must call find on modl, not tab > end > > def hi > tab = User > list(tab) > end > > Can be simplified as: > def list(modl) > modl.find(:all) > end > > def hi > list(User) > end > > -- > Andrew Timberlake > http://ramblingsonrails.com > http://www.linkedin.com/in/andrewtimberlake > > "I have never let my schooling interfere with my education" - Mark TwainHi andrews thanks for ur reply. its working. thanks for ur optimization too regards, shanmu -- 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 -~----------~----~----~----~------~----~------~--~---