I am currently working on re factoring my controllers and views to better follow the DRY principal. I have done significant work with the controllers but am struggling with the views... I have the standard type layout, a header (includes a navigation bar), then the content, followed by a footer. In the content section there is a title, basically the action name, and available actions followed by some dynamic content. The actions contain a create, list, and search button and other action specific actions. Right now those actions are defined in each page. I am trying to factor that out and create an action partial which will be shared amongst most of my controllers. How can I define a "default" list of actions and then when needed override those defaults? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
one approach would be using content_for. roughly in your layout (or wherever you want) you define a yield <%= yield :action_menu %> and in the views you would then declare content for that: <% content_for :action_menu %> <%= render :partial => "basic_menu" %> <% end %> in another one: <% content_for :action_menu %> <%= render :partial => "basic_menu" %> <%= link_to "another option", ...path to option... %> <% end %> or create them in whatever way you like, mixing partials with defaults and inplace code. http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001069 -- 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 -~----------~----~----~----~------~----~------~--~---
default scaffolding shows some code reuse, if that helps. On Tue, Apr 29, 2008 at 7:58 AM, predhme <kenp21-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am currently working on re factoring my controllers and views to > better follow the DRY principal. I have done significant work with the > controllers but am struggling with the views... > > I have the standard type layout, a header (includes a navigation bar), > then the content, followed by a footer. > > In the content section there is a title, basically the action name, > and available actions followed by some dynamic content. The actions > contain a create, list, and search button and other action specific > actions. Right now those actions are defined in each page. I am trying > to factor that out and create an action partial which will be shared > amongst most of my controllers. How can I define a "default" list of > actions and then when needed override those defaults? > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I have constructed something to that effect... layouts/global.html.erb <%= render :partial => "header" %> <%= render :partial => "navigation" %> <%= yield :actions %> <%= yield %> <%= render :partial => "footer" %> so for my views i need to declare the actions, most likely should be in a partial... the standard list <% content_for :actions %> <%= link_to "New", :action => "new" %> <%= link_to "List", :action => "list" %> <%= link_to "Search", :action => "search" %> <% end %> then i could have a set of other actions that aren''t ordinary. So i guess then in about 95% of my views i will have: <%= render :partial => "default_actions" %> and sometimes additional renders for other action sets I may need. Now my problem is that because I don''t always want to display the action menu, I cannot add the above render to my layout because then it would show all the time. So I would have to put the render in every one of my views when I want it. But seeing how it is needed more often than not, should I put the render call in my layout and a conditional statement to hide it when desired, I certainly do not want to clutter my views with conditional code when not needed. What would be the best way to handle this situation? On Apr 29, 10:32 am, Thorsten Mueller <rails-mailing-l...@andreas- s.net> wrote:> one approach would be using content_for. > roughly in your layout (or wherever you want) you define a yield > > <%= yield :action_menu %> > > and in the views you would then declare content for that: > <% content_for :action_menu %> > <%= render :partial => "basic_menu" %> > <% end %> > > in another one: > <% content_for :action_menu %> > <%= render :partial => "basic_menu" %> > <%= link_to "another option", ...path to option... %> > <% end %> > > or create them in whatever way you like, mixing partials with defaults > and inplace code. > > http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.h... > -- > 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 -~----------~----~----~----~------~----~------~--~---
Or multiple layouts. I''d tend to put it in the global layout, myself, so I don''t have to clutter the views with repeated code. On Wed, Apr 30, 2008 at 10:28 AM, predhme <kenp21-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have constructed something to that effect... > > layouts/global.html.erb > > <%= render :partial => "header" %> > <%= render :partial => "navigation" %> > <%= yield :actions %> > <%= yield %> > <%= render :partial => "footer" %> > > > so for my views i need to declare the actions, most likely should be > in a partial... the standard list > <% content_for :actions %> > <%= link_to "New", :action => "new" %> > <%= link_to "List", :action => "list" %> > <%= link_to "Search", :action => "search" %> > <% end %> > > then i could have a set of other actions that aren''t ordinary. So i > guess then in about 95% of my views i will have: > <%= render :partial => "default_actions" %> > > and sometimes additional renders for other action sets I may need. Now > my problem is that because I don''t always want to display the action > menu, I cannot add the above render to my layout because then it would > show all the time. So I would have to put the render in every one of > my views when I want it. But seeing how it is needed more often than > not, should I put the render call in my layout and a conditional > statement to hide it when desired, I certainly do not want to clutter > my views with conditional code when not needed. What would be the best > way to handle this situation? > > > > On Apr 29, 10:32 am, Thorsten Mueller <rails-mailing-l...@andreas- > > s.net> wrote: > > one approach would be using content_for. > > roughly in your layout (or wherever you want) you define a yield > > > > <%= yield :action_menu %> > > > > and in the views you would then declare content for that: > > <% content_for :action_menu %> > > <%= render :partial => "basic_menu" %> > > <% end %> > > > > in another one: > > <% content_for :action_menu %> > > <%= render :partial => "basic_menu" %> > > <%= link_to "another option", ...path to option... %> > > <% end %> > > > > or create them in whatever way you like, mixing partials with defaults > > and inplace code. > > > > http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.h... > > -- > > 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 -~----------~----~----~----~------~----~------~--~---