If I have : class X < ApplicationController def some_method ... end end and I have class Y < ApplicationController end How, from a method within class Y, can I call class X''s some_method ? TIA, RVince -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Seems the best solution is the straight OOP solution: class Y < X ... something = some_method .... end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 12 April 2010 15:07, RVince <rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Seems the best solution is the straight OOP solution: > > class Y < X > ... > something = some_method > .... > end >I''d say it depends on whether Y really IS AN X. If not, but they have similar roles, I''d say you''re better of doing this: class Z < ApplicationController def some_method ... end end class X < Z ... end class Y < Z ... end or more simply: module Z def some_method ... end end class X < ApplicationController include Z ... end class Y < ApplicationController include Z ... end You could also instantiate an X controller, but depending on the method you''re trying to call, you may need to do a bit of setup (pass in the request/response somehow so it can take over). Cheers, Andy -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Andy Jeffries wrote:> > I''d say it depends on whether Y really IS AN X. If not, but they have > similar roles, I''d say you''re better of doing this: > > class Z < ApplicationController > def some_method > ... > end > end > > class X < Z > ... > end > > class Y < Z > ... > end >I like this if ALL your controllers should have access to some_method> module Z > def some_method > ... > end > end > > class X < ApplicationController > include Z > ... > end > > class Y < ApplicationController > include Z > ... > end >I like this if some_method should only be available to some controllers. Depends on the application requirements as to which way I would go... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.