Using same partial with diff ajax requests

Im wondering what the best design implementation with DRY in mind in
the following situation. I have a number of situations where I am
rendering the same partial with different ajax requests. For example,
I have an inbox table and I have to link_to_remotes. One links to
viewing all messages and another links to show a single message. Im
wondering, does it make sense to use the same partial and create a
variable in the controller which could be used in an if else statement
within the view. like:

def show
@type = “show”
page.replace_html “inbox_message”, :partial => ‘message’, :locals =>
{:type => @type}

def index
@type = “show_all”
page.replace_html “inbox_message”, :partial => ‘message’, :locals =>
{:type => @type}

then in the _message partial i could have somehting like:
if @type == “show”
only show one message
show all messages

Is there a better way to do this? Would just creating two different
partials be any better? What about any performance issues?

Thanks, Dave

I think 2 partials would work nicely:


Listing Messages

    <%= render :partial => 'message', :collection => @messages %>


  • <%= message.title %> - <%= message.body %>
  • Aaron