Forum: Ruby on Rails render :update with status code?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-04-17 14:38
(Received via mailing list)
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 :)
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2007-04-17 15:30
(Received via mailing list)
Daniel Smedegaard Buus 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/...

It's the same in current trunk:

http://dev.rubyonrails.org/browser/trunk/actionpac...

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.
3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-04-20 17:54
(Received via mailing list)
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 James <m...@bigpond.net.au> wrote:
> not being sent into the render_javascript call on this line:
>
> http://dev.rubyonrails.org/browser/tags/rel_1-2-3/......
>
> It's the same in current trunk:
>
> http://dev.rubyonrails.org/browser/trunk/actionpac......
>

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 :)
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2007-04-20 23:58
(Received via mailing list)
Daniel Smedegaard Buus 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.
3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-04-24 12:20
(Received via mailing list)
On Apr 20, 11:57 pm, Mark Reginald James <m...@bigpond.net.au> 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! :D Thanks :)
This topic is locked and can not be replied to.