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

Hi –

On Thu, 23 Aug 2007, [email protected] wrote:

‘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

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