# How do you trigger an xml response for "respond\_to do |format|'

**URL:** <https://www.ruby-forum.com/t/how-do-you-trigger-an-xml-response-for-respond-to-do-format/160732>\
**Category:** Rails\
**Created:** [February 19, 2009, 7:02am UTC](https://www.ruby-forum.com/t/how-do-you-trigger-an-xml-response-for-respond-to-do-format/160732 "2009-02-19T07:02:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 19, 2009, 7:02am UTC](https://www.ruby-forum.com/t/how-do-you-trigger-an-xml-response-for-respond-to-do-format/160732/1 "2009-02-19T07:02:21Z")

</div>

Hi - how do you trigger an xml response for "respond\_to do |format|’ ?

Wondering why the following isn’t working for me (i.e. triggers HTML  
response)

------------------view ----------------  
\<% _remote\_form\_for_ :bi\_allocation, @bi\_allocation, :url =\> {  
:controller  
=\> “bi\_allocation”, _:action =\> “r\_create”_} do |f| %\>  
\<%= f.text\_field :amount, :size =\> 10 %\>  
\<%= submit\_tag ‘Create’ %\>  
\<% end %\>

------------ controller ---------------------  
_def r\_create_  
@bi\_allocation = BiAllocation.new(params[:bi\_allocation])  
respond\_to do |format|  
if @bi\_allocation.save  
format.html raise("\*\*\* _HITS THIS LINE_ \*\*\*")  
format.xml { render :xml =\> @bi\_allocation, :status =\>  
:created,  
:location =\> @bi\_allocation} _# Doesn’t hit this line_  
else  
format.html { render :action =\> “xxxx” }  
format.xml { render :xml =\> @bi\_allocation.errors }  
end  
end  
end

thanks

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 19, 2009, 8:05am UTC](https://www.ruby-forum.com/t/how-do-you-trigger-an-xml-response-for-respond-to-do-format/160732/2 "2009-02-19T08:05:35Z")

</div>

try calling it with :format =\> ‘xml’

\<%= link\_to “link\_name”, :controller =\> ‘controller\_name’, :action =\>  
‘action\_name’, :format =\> ‘xml’ %\>

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [February 19, 2009, 11:48am UTC](https://www.ruby-forum.com/t/how-do-you-trigger-an-xml-response-for-respond-to-do-format/160732/3 "2009-02-19T11:48:45Z")

</div>

2009/2/19 MaD [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> try calling it with :format =\> ‘xml’
> 
> \<%= link\_to “link\_name”, :controller =\> ‘controller\_name’, :action =\>  
> ‘action\_name’, :format =\> ‘xml’ %\>

tks - the remote\_form\_for method doesn’t mention a “:format” parameter?  
actually the “link\_to” method (which you used in your example) I see  
doesn’t mention this either? Just wondering how one would have found  
out  
about this being an option here?

regards  
Greg
