KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-23 14:48 UTC
Multiple views for the same action?
I expect those that have taken the time to read this crazy title think, ! Whoa ! what terrible newbie question is this?? I am writing a generic inventory application that handles a WIDE variety of inventory items whose fields can be very different. My objective is to write one application and based on the CATEGORY of the item, to display the appropriate new, edit, index, show templates (obviously showing the pertinent fields). I''ve thought that I could have one terribly long .rhtml of each and have a <% case statement %> to control what rhtml lines are presented to the user. Is this the ''smart'' way to approach this? Thank you, Kathy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-23 15:15 UTC
Re: Multiple views for the same action?
Hi -- On Thu, 23 Aug 2007, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > I expect those that have taken the time to read this crazy title > think, ! Whoa ! what terrible newbie question is this?? > I am writing a generic inventory application that handles a WIDE > variety of inventory items whose fields can be very different. My > objective is to write one application and based on the CATEGORY of the > item, to display the appropriate new, edit, index, show templates > (obviously showing the pertinent fields). I''ve thought that I could > have one terribly long .rhtml of each and have a <% case statement %> > to control what rhtml lines are presented to the user. Is this the > ''smart'' way to approach this? > Thank you, > KathyMy inclination would be to do the branching in the controller, and do a ''render'' command for the right template. And/or: you could have multiple partial templates, and set a name in the controller and then do: <%= render :partial => @partial_name .... %> in the view. I''m not totally opposed to if/else (or case) logic in views. I sometimes do things like: <% if @admin_session %> ...show a delete button... <% end %> But when it gets too long, it''s a sign to me that it''s time to split it out into multiple templates, full or partial. I think it would also be easier to have one or more directories with, so to speak, an inventory of inventory forms, rather than have it all inlined in one template. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
rather than using <% if @admin_session %> you should look into using a helper method with a block such as: <% admin_content do -%> information for admins only <% end %> and then in your helper: def admin_content(&block) yield if session[:user].is_admin? end that way if you change the way administrator access is handled, you don''t have to change every "if @admin_session" instance. Adam On 8/23/07, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > Hi -- > > On Thu, 23 Aug 2007, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > > > I expect those that have taken the time to read this crazy title > > think, ! Whoa ! what terrible newbie question is this?? > > I am writing a generic inventory application that handles a WIDE > > variety of inventory items whose fields can be very different. My > > objective is to write one application and based on the CATEGORY of the > > item, to display the appropriate new, edit, index, show templates > > (obviously showing the pertinent fields). I''ve thought that I could > > have one terribly long .rhtml of each and have a <% case statement %> > > to control what rhtml lines are presented to the user. Is this the > > ''smart'' way to approach this? > > Thank you, > > Kathy > > My inclination would be to do the branching in the controller, and do > a ''render'' command for the right template. And/or: you could have > multiple partial templates, and set a name in the controller and then > do: > > <%= render :partial => @partial_name .... %> > > in the view. > > I''m not totally opposed to if/else (or case) logic in views. I > sometimes do things like: > > <% if @admin_session %> > > ...show a delete button... > > <% end %> > > But when it gets too long, it''s a sign to me that it''s time to split > it out into multiple templates, full or partial. > > I think it would also be easier to have one or more directories with, > so to speak, an inventory of inventory forms, rather than have it all > inlined in one template. > > > David > > -- > * Books: > RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---