# Conditional RJS partial rendering based on request source

**URL:** <https://www.ruby-forum.com/t/conditional-rjs-partial-rendering-based-on-request-source/148420>\
**Category:** Rails\
**Created:** [September 12, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/conditional-rjs-partial-rendering-based-on-request-source/148420 "2008-09-12T17:25:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [September 12, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/conditional-rjs-partial-rendering-based-on-request-source/148420/1 "2008-09-12T17:25:28Z")

</div>

Hi,

I’m not sure if this is a problem or just part of doing business with  
an AJAX based interface.

I have a create actions that renders a partial via RJS.

page.insert\_html :top, ‘addresses’, { :partial =\> ‘addresses/  
address’, :object =\> @address }

However, I call this create method from different points within the  
application and require the resulting @address object rendered in  
slightly different ways (coded up in two different partials) depending  
on which page they made the request.

The actual object creation in the create method is the same no matter  
where it is called but the view needs to differ.

Is there an elegant way to handle this without creating two create  
actions with identical create logic (extract to function?), for  
example:

def checkout\_create  
some\_creation\_logic  
responds\_to do |format|  
format.js #renders and inserts address\_partial\_1  
end  
end

def create  
some\_creation\_logic  
responds\_to do |format|  
format.js #renders and inserts address\_partial\_2  
end  
end

Thanks.
