I''m pretty new to Rails and have an issue which I can''t quite get my head around as to the architecturally ''correct'' way of doing it. Problem relates to what I kinda call sub-controllers. The scenario is this: I have a series of pages, on which is a panel of some form containing some information (think the user panel on gitHub top right). So, in my app, I have controllers that generate the data for the pages and render out the responses which is fine, but when it comes to this panel, it seems to me that you would want some sort of controller action dedicated to generating this panel and it''s view. Question is, how do you go about doing this? How do I render a ''sub controller'' from within a view? -- 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 -~----------~----~----~----~------~----~------~--~---
Hey Neil, Well, I''d go about it with a partial for the actual view part. If you simply need to just display it on a couple of actions, use a before_filter to call a method that sets variables only on those actions which require the submenu... then in your layout or view check that the variable is set and render the partial. Otherwise, if you have a authentication system, set the variables in there. restful_authentication does this by providing logged_in? and current_user for you. Hope that makes sense. :) John On Apr 1, 4:04 am, Neil Middleton <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m pretty new to Rails and have an issue which I can''t quite get my > head around as to the architecturally ''correct'' way of doing it. > > Problem relates to what I kinda call sub-controllers. The scenario is > this: > > I have a series of pages, on which is a panel of some form containing > some information (think the user panel on gitHub top right). > > So, in my app, I have controllers that generate the data for the pages > and render out the responses which is fine, but when it comes to this > panel, it seems to me that you would want some sort of controller action > dedicated to generating this panel and it''s view. > > Question is, how do you go about doing this? How do I render a ''sub > controller'' from within a view? > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
it does partly - although I''m thinking more generically. For instance, let''s take the navigation for an app where it''s state is dependant on some data in the DB. I don''t really want my page action to have to know anything about the nav at all, as that''s the layouts job to know what''s on the page, but I require a controller to provide the navigation with data. From what I understand of partials these are kinda headless in that they render a given variable, but don''t have any interaction with the controller per se. How do I go about rendering in this way? How do I let the layout kick of code to render chunks of a page that contain data without contaminating my page actions? Neil On Wed, Apr 1, 2009 at 6:01 PM, John Yerhot <joyerhot-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey Neil, > > Well, I''d go about it with a partial for the actual view part. If you > simply need to just display it on a couple of actions, use a > before_filter to call a method that sets variables only on those > actions which require the submenu... then in your layout or view check > that the variable is set and render the partial. > > Otherwise, if you have a authentication system, set the variables in > there. restful_authentication does this by providing logged_in? and > current_user for you. > > Hope that makes sense. :) > > John > > > On Apr 1, 4:04 am, Neil Middleton <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > I''m pretty new to Rails and have an issue which I can''t quite get my > > head around as to the architecturally ''correct'' way of doing it. > > > > Problem relates to what I kinda call sub-controllers. The scenario is > > this: > > > > I have a series of pages, on which is a panel of some form containing > > some information (think the user panel on gitHub top right). > > > > So, in my app, I have controllers that generate the data for the pages > > and render out the responses which is fine, but when it comes to this > > panel, it seems to me that you would want some sort of controller action > > dedicated to generating this panel and it''s view. > > > > Question is, how do you go about doing this? How do I render a ''sub > > controller'' from within a view? > > -- > > Posted viahttp://www.ruby-forum.com/. > > >-- Neil Middleton --~--~---------~--~----~------------~-------~--~----~ 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 use some inheritance and before_filters to handle this. class ApplicationController < ActionController::Base def load_panel_data @data = Data.all end end class OtherController < ActionController::Base before_filter :load_panel_data ... your normal actions ... end In your layout you can now render a partial that is expecting the @data variable. before_filters are inheritable and configurable. http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html On Apr 1, 7:38 pm, Neil Middleton <neil.middle...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> it does partly - although I''m thinking more generically. For instance, let''s > take the navigation for an app where it''s state is dependant on some data in > the DB. I don''t really want my page action to have to know anything about > the nav at all, as that''s the layouts job to know what''s on the page, but I > require a controller to provide the navigation with data. > From what I understand of partials these are kinda headless in that they > render a given variable, but don''t have any interaction with the controller > per se. > > How do I go about rendering in this way? How do I let the layout kick of > code to render chunks of a page that contain data without contaminating my > page actions? > > Neil > > > > > > On Wed, Apr 1, 2009 at 6:01 PM, John Yerhot <joyer...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hey Neil, > > > Well, I''d go about it with a partial for the actual view part. If you > > simply need to just display it on a couple of actions, use a > > before_filter to call a method that sets variables only on those > > actions which require the submenu... then in your layout or view check > > that the variable is set and render the partial. > > > Otherwise, if you have a authentication system, set the variables in > > there. restful_authentication does this by providing logged_in? and > > current_user for you. > > > Hope that makes sense. :) > > > John > > > On Apr 1, 4:04 am, Neil Middleton <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > I''m pretty new to Rails and have an issue which I can''t quite get my > > > head around as to the architecturally ''correct'' way of doing it. > > > > Problem relates to what I kinda call sub-controllers. The scenario is > > > this: > > > > I have a series of pages, on which is a panel of some form containing > > > some information (think the user panel on gitHub top right). > > > > So, in my app, I have controllers that generate the data for the pages > > > and render out the responses which is fine, but when it comes to this > > > panel, it seems to me that you would want some sort of controller action > > > dedicated to generating this panel and it''s view. > > > > Question is, how do you go about doing this? How do I render a ''sub > > > controller'' from within a view? > > > -- > > > Posted viahttp://www.ruby-forum.com/. > > -- > Neil Middleton--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---