Render :update with status code?

Hey :slight_smile:

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 :frowning: 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 :slight_smile:

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

It’s the same in current trunk:

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.

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

On Apr 17, 3:28 pm, Mark Reginald J. [email protected] 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

It’s the same in current trunk:

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 :wink:

Cheers,
Daniel :slight_smile:

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 :wink:

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.

On Apr 20, 11:57 pm, Mark Reginald J. [email protected] 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! :smiley: Thanks :slight_smile: