Hi, can anyone tell me - is it possible to pass a string name equivalent of a model name(example:- have a model called food_dept and i am passing the string "food_dept" to a method) and then covert(or cast) it to its original model equivalent so that i can use its object in the called method. and why i am i trying to this manner is because i want to avoid passing an object which will make it very heavy. i think there should be some better elegant manner of doing this. can any one help me with this? ciao -AG --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 5/7/07, arjun ghosh <arjun4ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > can anyone tell me - is it possible to pass a string name equivalent of a > model name(example:- have a model called food_dept and i am passing the > string "food_dept" to a method) and then covert(or cast) it to its original > model equivalent so that i can use its object in the called method. and why > i am i trying to this manner is because i want to avoid passing an object > which will make it very heavy. i think there should be some better elegant > manner of doing this. can any one help me with this? > ciao > -AG > > > >"food_dept".classify.constantize => FoodDept Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks pat for the quick help...can u point me to a directions where i can learn these things...a book or pdf..it is embarrassing to ask these simple stuff from u guys...though thanks again -ciao AG On 5/7/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 5/7/07, arjun ghosh <arjun4ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > can anyone tell me - is it possible to pass a string name equivalent of > a > > model name(example:- have a model called food_dept and i am passing the > > string "food_dept" to a method) and then covert(or cast) it to its > original > > model equivalent so that i can use its object in the called method. and > why > > i am i trying to this manner is because i want to avoid passing an > object > > which will make it very heavy. i think there should be some better > elegant > > manner of doing this. can any one help me with this? > > ciao > > -AG > > > > > > > > > "food_dept".classify.constantize => FoodDept > > Pat > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 5/7/07, arjun ghosh <arjun4ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks pat for the quick help...can u point me to a directions where i can > learn these things...a book or pdf..it is embarrassing to ask these simple > stuff from u guys...though thanks again > -ciao > AGRuby for Rails is probably the best Ruby book out there, in my opinion. It''s not really meant to teach you Rails in depth (that''s what Agile WebDev w/Rails is for), but rather to show and explain the Ruby that actually makes Rails possible. Open classes, duck typing, metaprogramming, etc. However I''ll also say that I think it''s perfectly acceptable to ask that particular question on this list :) It gets asked every once in a while, but I couldn''t find anything with a quick google. You should spend more time than I did probably :) but you also shouldn''t be embarrassed to ask a question. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 5/7/07, arjun ghosh <arjun4ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > can anyone tell me - is it possible to pass a string name equivalent of a > model name(example:- have a model called food_dept and i am passing the > string "food_dept" to a method) and then covert(or cast) it to its original > model equivalent so that i can use its object in the called method. and why > i am i trying to this manner is because i want to avoid passing an object > which will make it very heavy.Unless I''m missing something (which is usually the case :) ), there seems to be a misunderstanding of how variables work in Ruby. When you pass food_dept (or FoodDept) to another method, you are not passing the object itself, but rather a variable which holds a reference to the object. What you suggest, passing its name and then discovering the class from its name is far more expensive than simply using the variable. Cheers, David>i think there should be some better elegant > manner of doing this. can any one help me with this? > ciao > -AG > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---