Dear user community, I know that I can access the controller that is called by using params[:controller] . I need to obtain the model name for a find command and I was wondering if there was a built in way of obtaining this name. If I can''t obtain it I have to ways to obtain it, by using the controller and modding the string as I go through it or creating a database and find the association in the database. I would much rather use a built in variable or method to obtain this information. Any and all help is appreciated thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What exactly do you want to do with the model ''name''. I believe you already know your model class name. And if you are talking about getting reference of the model object in your controller then you have the option of creating sessions or using a global hash. Please throw in more details about your requirement. Thanks, ~Shishir On Sep 26, 5:46 pm, White Wizzard <The.White.Wizz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear user community, > > I know that I can access the controller that is called by using > params[:controller] . I need to obtain the model name for a find > command and I was wondering if there was a built in way of obtaining > this name. If I can''t obtain it I have to ways to obtain it, by using > the controller and modding the string as I go through it or creating > a database and find the association in the database. > > I would much rather use a built in variable or method to obtain this > information. > > Any and all help is appreciated > > thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Is it inside of a model? If so, you could likely do something like... self.class.find(:first) ...or whatever find command you''re looking for. If that''s not what you need, then we need more details, please. :) --Jeremy On 9/26/07, White Wizzard <The.White.Wizzard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Dear user community, > > I know that I can access the controller that is called by using > params[:controller] . I need to obtain the model name for a find > command and I was wondering if there was a built in way of obtaining > this name. If I can''t obtain it I have to ways to obtain it, by using > the controller and modding the string as I go through it or creating > a database and find the association in the database. > > I would much rather use a built in variable or method to obtain this > information. > > Any and all help is appreciated > > thanks > > > > >-- http://www.jeremymcanally.com/ My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.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 -~----------~----~----~----~------~----~------~--~---
You can do something like this. case1: Array of object returned by your query like this x = Product.find(:all) # may what ever query you want. model_name = x.first.class puts model_name # outputs Product case2: Your query returns only single object x = Product.find(:first) # may what ever query you want. model_name = x.class puts model_name # outputs Product On Sep 26, 5:46 pm, White Wizzard <The.White.Wizz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear user community, > > I know that I can access the controller that is called by using > params[:controller] . I need to obtain the model name for a find > command and I was wondering if there was a built in way of obtaining > this name. If I can''t obtain it I have to ways to obtain it, by using > the controller and modding the string as I go through it or creating > a database and find the association in the database. > > I would much rather use a built in variable or method to obtain this > information. > > Any and all help is appreciated > > thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---