In controller ,there is something like self. to call the controller itsself if i want to call model that belong to that controller in controller, How could i do. Thank, Golf -- Posted via http://www.ruby-forum.com/.
Hi Models don''t belong to controllers. They are two separate classes that, to make things more practical, often have a similar name. You could just as easily have a Post model and a BlogController and Rails wouldn''t know the difference. If you''re trying to guess the name of model from the controller that deals with creating and maintaining its records you could try: def get_model self.class.to_s.gsub("Controller","").singularize.constantize end This would return Comment if called in the CommentsController. Hope that helps? Gavin http://handyrailstips.com On Jul 20, 6:35 am, "Thriving K." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> In controller ,there is something like self. to call the controller > itsself > > if i want to call model that belong to that controller in controller, > How could i do. > > Thank, > Golf > -- > Posted viahttp://www.ruby-forum.com/.
Thank you, i will try -- Posted via http://www.ruby-forum.com/.
In Ruby there is always "something called self". It''s really worth understanding what it is at any given time. Dave Thomas gave a presentation on the Ruby Object Model at Scotland on Rails this year. The video is available: http://scotland-on-rails.s3.amazonaws.com/2A04_DaveThomas-SOR.mp4 Enjoy! Bryan
Bryan Ash wrote:> In Ruby there is always "something called self". It''s really worth > understanding what it is at any given time. > > Dave Thomas gave a presentation on the Ruby Object Model at Scotland > on Rails this year. The video is available: > http://scotland-on-rails.s3.amazonaws.com/2A04_DaveThomas-SOR.mp4 > > Enjoy! > BryanThank you for Bryan too :) but it seem that link for the video is corrupted,or else it is problems of my internet connection :( Does anyone has the similar video. -- Posted via http://www.ruby-forum.com/.
2009/7/20 Thriving K. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > In controller ,there is something like self. to call the controller > itsself > > if i want to call model that belong to that controller in controller, > How could i do. >I am not sure what you are asking here, could you explain in a little more detail what you are trying to do? With an example if possible. Colin
Models dont belong to a controller afaik 2009/7/20, Thriving K. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > In controller ,there is something like self. to call the controller > itsself > > if i want to call model that belong to that controller in controller, > How could i do. > > Thank, > Golf > -- > Posted via http://www.ruby-forum.com/. > > > >-- Von meinen Mobilgerät aus gesendet