# Render :update with status code?

**URL:** <https://www.ruby-forum.com/t/render-update-with-status-code/92250>\
**Category:** Rails\
**Created:** [April 17, 2007, 2:38pm UTC](https://www.ruby-forum.com/t/render-update-with-status-code/92250 "2007-04-17T14:38:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [April 17, 2007, 2:38pm UTC](https://www.ruby-forum.com/t/render-update-with-status-code/92250/1 "2007-04-17T14:38:10Z")

</div>

Hey 🙂

I’d like to be able to update the page while setting the status code  
of the response, so that I can respond to the success/fail state of an  
AJAX call, AND update elements on the page via RJS, regardless of  
whether the status is good or bad.

AFAICS, I can only do,  
render :nothing =\> true, :status =\> 500  
to let the status code punch through to my web page where I have a  
function to execute on :success.

But, I want to do something like,  
render :update, :status =\> 500 do |page|  
# Update the messages console:  
page[‘messages\_console’].replace :partial =\> ‘/manage/  
messages\_console’, :locals =\> { :model =\> model }  
end

I’ve tried different variations, but I can’t get it to work ☹ Rails  
responds with status code 200 whenever I use the render :update  
version. I want to update my messages\_console div with text about want  
went wrong AND do that with a status 500 header, so that my :success  
function won’t execute…

Possible?

Thanks in advance,  
Daniel 🙂

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [April 17, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/render-update-with-status-code/92250/2 "2007-04-17T15:30:23Z")

</div>

Daniel Smedegaard B. wrote:

> I’d like to be able to update the page while setting the status code  
> of the response, so that I can respond to the success/fail state of an  
> AJAX call, AND update elements on the page via RJS, regardless of  
> whether the status is good or bad.  
> …  
> But, I want to do something like,  
> render :update, :status =\> 500 do |page|

I had a look into this and saw that options[:status] is  
not being sent into the render\_javascript call on this line:

[http://dev.rubyonrails.org/browser/tags/rel\_1-2-3/actionpack/lib/action\_controller/base.rb#L770](http://dev.rubyonrails.org/browser/tags/rel_1-2-3/actionpack/lib/action_controller/base.rb#L770)

It’s the same in current trunk:

[http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action\_controller/base.rb#L819](http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/base.rb#L819)

I couldn’t find any tickets that address this.

So unless there’s another way to set a response code, your  
best option is to remove the :success option and send the  
appropriate Javascript from the server. The :failure option  
can instead be used for things like response timeout.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [April 20, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/render-update-with-status-code/92250/3 "2007-04-20T17:54:28Z")

</div>

Hi Mark, thanks for replying - and sorry for the late response, I have  
a lot of things on my mind ATM 🙂

On Apr 17, 3:28 pm, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> not being sent into the render\_javascript call on this line:
> 
> [http://dev.rubyonrails.org/browser/tags/rel\_1-2-3/actionpack/lib/acti](http://dev.rubyonrails.org/browser/tags/rel_1-2-3/actionpack/lib/acti)…
> 
> It’s the same in current trunk:
> 
> [http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action\_contro](http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_contro)…

Do you know if there’s a particular reason for this (like  
render\_javascript being significantly different), or if one could  
modify it more easily?

> I couldn’t find any tickets that address this.
> 
> So unless there’s another way to set a response code, your  
> best option is to remove the :success option and send the  
> appropriate Javascript from the server. The :failure option  
> can instead be used for things like response timeout.

Yeah, but as far as my brain works, I don’t know how I would go about  
that… But I am learning quite a lot lately, so it might just dawn on  
me anytime 😉

Cheers,  
Daniel 🙂

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [April 20, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/render-update-with-status-code/92250/4 "2007-04-20T23:58:12Z")

</div>

Daniel Smedegaard B. wrote:

> > I had a look into this and saw that options[:status] is  
> > not being sent into the render\_javascript call on this line:
> 
> Do you know if there’s a particular reason for this (like  
> render\_javascript being significantly different), or if one could  
> modify it more easily?

No, it seems to be an oversight.

> > So unless there’s another way to set a response code, your  
> > best option is to remove the :success option and send the  
> > appropriate Javascript from the server. The :failure option  
> > can instead be used for things like response timeout.
> 
> Yeah, but as far as my brain works, I don’t know how I would go about  
> that… But I am learning quite a lot lately, so it might just dawn on  
> me anytime 😉

Just remove the :success and :failure options from the AJAX call,  
and change your controller code so that instead of sending a non-OK  
status you send Javascript that has the same effect as your :failure  
code.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [April 24, 2007, 12:20pm UTC](https://www.ruby-forum.com/t/render-update-with-status-code/92250/5 "2007-04-24T12:20:07Z")

</div>

On Apr 20, 11:57 pm, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > So unless there’s another way to set a response code, your  
> > > status you send Javascript that has the same effect as your :failure  
> > > code.

Oh yes, of course! 😃 Thanks 🙂
