# Using same partial with diff ajax requests.

**URL:** <https://discuss.rubyonrails.org/t/using-same-partial-with-diff-ajax-requests/39258>\
**Category:** rubyonrails-talk\
**Created:** [February 11, 2009, 5:05am UTC](https://discuss.rubyonrails.org/t/using-same-partial-with-diff-ajax-requests/39258 "2009-02-11T05:05:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_L](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dave\_L](https://discuss.rubyonrails.org/u/Dave_L)\
**Post date:** [February 11, 2009, 5:05am UTC](https://discuss.rubyonrails.org/t/using-same-partial-with-diff-ajax-requests/39258/1 "2009-02-11T05:05:18Z")

</div>

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} end

def index @type = "show\_all" page.replace\_html "inbox\_message", :partial =\> 'message', :locals =\> {:type =\> @type} end

then in the \_message partial i could have somehting like: if @type == "show" &nbsp;&nbsp;only show one message else &nbsp;&nbsp;show all messages end

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

Thanks, Dave

---

<div class="post-metadata">

**Author:** ![Aaron5](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Aaron5](https://discuss.rubyonrails.org/u/Aaron5)\
**Post date:** [February 11, 2009, 8:35am UTC](https://discuss.rubyonrails.org/t/using-same-partial-with-diff-ajax-requests/39258/2 "2009-02-11T08:35:57Z")

</div>

I think 2 partials would work nicely:

# \_messages.html.erb \<h1\>Listing Messages\</h1\> \<ul\> &nbsp;&nbsp;\<%= render :partial =\> 'message', :collection =\> @messages %\> \</ul\>

# \_message.html.erb \<li\>\<%= message.title %\> - \<%= message.body %\>\</li\>

Aaron
