# How to specify the response format in an asynchronous post action

**URL:** <https://www.ruby-forum.com/t/how-to-specify-the-response-format-in-an-asynchronous-post-action/145161>\
**Category:** Rails\
**Created:** [August 6, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/how-to-specify-the-response-format-in-an-asynchronous-post-action/145161 "2008-08-06T16:25:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [August 6, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/how-to-specify-the-response-format-in-an-asynchronous-post-action/145161/1 "2008-08-06T16:25:08Z")

</div>

I do asynchronous request via remote\_form\_for,I expect it will update  
partial content within current page, but it end up redirect to a new  
page,I guess may be cause controller consider ’ format.html’ was I  
need.so I want to try other reponse format.The problem is I don know  
how to specify the response format in post action.

whether the approach is set ‘accpt’ in request Header? If it is,How?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [August 7, 2008, 8:51am UTC](https://www.ruby-forum.com/t/how-to-specify-the-response-format-in-an-asynchronous-post-action/145161/2 "2008-08-07T08:51:28Z")

</div>

Thanks Nate L., rjs works!

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [August 6, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/how-to-specify-the-response-format-in-an-asynchronous-post-action/145161/3 "2008-08-06T21:59:26Z")

</div>

Vince wrote:

> I do asynchronous request via remote\_form\_for,I expect it will update  
> partial content within current page, but it end up redirect to a new  
> page,I guess may be cause controller consider ’ format.html’ was I  
> need.so I want to try other reponse format.The problem is I don know  
> how to specify the response format in post action.
> 
> whether the approach is set ‘accpt’ in request Header? If it is,How?

Not sure I fully understand your question, but the remote\_form\_for  
method is a post via AJAX and so you need to setup your controller to  
expect a ajax request.

Here is what I do:

respond\_to do |format|  
format.js  
end

Then create an rjs template named the same as your action in the  
controller that updates the part of the page you want updated.

So if your action is called Create, you would create a rjs template  
called create.rjs and in that template you would have

page.replace\_html :name\_of\_element, :partial =\> ‘new\_content’

which will replace the id of the element you want to replace with the  
\_new\_content.erb partial.

Hope that helps.
