Parama
2008-Jan-24 22:47 UTC
What is the best way to reuse a controller''s action and views?
What is the best way to reuse a controller''s actions and views? Lets say I have an application that has controller: SampleController<ApplicationController This controller would be accessable from the following url http:localhost:3000/sample/blah_action I need to create another controller that has the actions of this controller, plus some more actions of its own If I created another controller: ImageController < SampleController Then this url : http://localhost:3000/sample/image/blah_action would take me to the ImageController if the actions exist exists in it. however if the action doesn''t exist, it should use the parent''s actions and views. What is the best way to do this? 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 -~----------~----~----~----~------~----~------~--~---
Thomas Maurer
2008-Jan-24 23:15 UTC
Re: What is the best way to reuse a controller''s action and views?
I''d extract the common actions in a module and include it in both controllers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Parama
2008-Jan-25 02:00 UTC
Re: What is the best way to reuse a controller''s action and views?
But I need the views associated with that action also. how would you include the views? Are there any way to do this more cleanly through controller inheritance? On Jan 24, 6:15 pm, Thomas Maurer <thomas.mau...-tZz5GHO4c1f463JZfw7VRw@public.gmane.org> wrote:> I''d extract the common actions in a module and include it in both > controllers.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nathan Esquenazi
2008-Jan-25 02:08 UTC
Re: What is the best way to reuse a controller''s action and
I am confused, you pretty much seemed to answer your own question. There is no reason you can''t just use controller inheritance: class ParentsController < AC::Base def show # code here respond_to do |format| format.html { render :template => ''parent/show'' } end end end and then make /views/parents/show.html.erb and then to extend: class ChildrensController < ParentsController end -- 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 -~----------~----~----~----~------~----~------~--~---
Bas van Westing
2008-Jan-25 11:06 UTC
Re: What is the best way to reuse a controller''s action and
Hi, I has the same issue when I wanted a SOAP controller (ActionWebService) to reuse my Restful logic in the normal controllers. Inheritance was not an option, because i needed logic from mulitple Restful controllers (mixin would override shared method names, so that didn''t work). I ended up using a render_component statement (with response format XML) from the SOAP Controller towards the Restful controller, which is really ugly because that means I was actually pretending the SOAP controller to be an external application. But it works fine en it helps me keep my code DRY (but slower). If anybody has a better idea to solve this please let me know. Regards, Bas On Jan 25, 3:08 am, Nathan Esquenazi <rails-mailing-l...@andreas- s.net> wrote:> I am confused, you pretty much seemed to answer your own question. There > is no reason you can''t just use controller inheritance: > > class ParentsController < AC::Base > def show > # code here > respond_to do |format| > format.html { render :template => ''parent/show'' } > end > end > end > > and then make /views/parents/show.html.erb > > and then to extend: > > class ChildrensController < ParentsController > > end > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
tyler.a.montgomery-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-25 15:36 UTC
Re: What is the best way to reuse a controller''s action and views?
Check out RailsEngines: http://rails-engines.org/introduction On Jan 24, 7:00 pm, Parama <para...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> But I need the views associated with that action also. how would you > include the views? > > Are there any way to do this more cleanly through controller > inheritance? > > On Jan 24, 6:15 pm, Thomas Maurer <thomas.mau...-tZz5GHO4c1f463JZfw7VRw@public.gmane.org> wrote: > > > I''d extract the common actions in a module and include it in both > > controllers.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hendy Irawan
2008-Feb-06 13:53 UTC
What is the best way to reuse a controller''s action and views?
On Jan 25, 2008 10:36 PM, tyler.a.montgomery-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org < tyler.a.montgomery-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Check out RailsEngines: http://rails-engines.org/introduction >Have to agree on the RailsEngines. If your views are non-changing then you may consider a combination of: * generator script to generate views and controllers * the controllers are actually ''dumb'' ones that simply include a module(s) * the module(s) are in the plugin, including the Rails generators --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---