Hi there, how would I get the HTTP response code (200 OK, 500, etc...) from a controller after a request have been ''served''? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I was able to get the response status after_filter by doing response.headers["Status"], but it *only* displays the 200 and 302 codes. Any ideas how I get get the others (404, 500, etc...) as well? Thanks Mark wrote:> Hi there, how would I get the HTTP response code (200 OK, 500, etc...) > from a controller after a request have been ''served''? > > > Thanks-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''ll have to hook it somewhere else (eg, in Mongrel or a monkey/ mixin patch to ActionController::Base). Your controller won''t be consulted in the case of a 404 or 500 error. Those are usually generated from exceptions. Is there a reason you need to know about these status codes in your controller? On Mar 21, 11:01 am, Mark <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I was able to get the response status after_filter by doing > response.headers["Status"], but it *only* displays the 200 and 302 > codes. Any ideas how I get get the others (404, 500, etc...) as well? > > Thanks > > Mark wrote: > > Hi there, how would I get the HTTP response code (200 OK, 500, etc...) > > from a controller after a request have been ''served''? > > > Thanks > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eden Li, I see what you mean. The reason why I need those status codes is for a personal project that I''m doing and I need to store those codes in the DB as-they-happen. Could you give me a starting point for the monkey/mixin patch? Thanks Eden Li wrote:> You''ll have to hook it somewhere else (eg, in Mongrel or a monkey/ > mixin patch to ActionController::Base). Your controller won''t be > consulted in the case of a 404 or 500 error. Those are usually > generated from exceptions. > > Is there a reason you need to know about these status codes in your > controller?-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tjackiw-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-21 04:42 UTC
Re: Getting HTTP response code from a controller
Cool, I could have a use for that as well. Let me know if you guys figure it out. In the meantime I''ll try to do it too. -- Thiago Jackiw acts_as_solr => http://acts-as-solr.rubyforge.org Sitealizer Web Stats => http://sitealizer.rubyforge.org On Mar 20, 9:36 pm, Mark <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Eden Li, > > I see what you mean. The reason why I need those status codes is for a > personal project that I''m doing and I need to store those codes in the > DB as-they-happen. > > Could you give me a starting point for the monkey/mixin patch? > > Thanks > > Eden Li wrote: > > You''ll have to hook it somewhere else (eg, in Mongrel or a monkey/ > > mixin patch to ActionController::Base). Your controller won''t be > > consulted in the case of a 404 or 500 error. Those are usually > > generated from exceptions. > > > Is there a reason you need to know about these status codes in your > > controller? > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here''s a first stab...
# lib/final_response.rb
module FinalResponse
def self.included(base)
base.class_eval do
alias_method :process_without_final_response, :process
alias_method :process, :process_with_final_response
end
end
def process_with_final_response(*args)
process_without_final_response(*args)
ensure
final_response if respond_to?(:final_response)
end
end
# app/controllers/my_controller.rb
class MyController < ActionController::Base
include FinalResponse
def final_response
logger.info("status = #{headers[''Status'']}")
end
def action
raise
end
end
Your final_response method won''t have access to the session, but
you''ll still be OK to access models.
There''s probably a better way to do this, but this should work...
On Mar 21, 12:36 pm, Mark
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Eden Li,
>
> I see what you mean. The reason why I need those status codes is for a
> personal project that I''m doing and I need to store those codes in
the
> DB as-they-happen.
>
> Could you give me a starting point for the monkey/mixin patch?
>
> Thanks
>
> Eden Li wrote:
> > You''ll have to hook it somewhere else (eg, in Mongrel or a
monkey/
> > mixin patch to ActionController::Base). Your controller
won''t be
> > consulted in the case of a 404 or 500 error. Those are usually
> > generated from exceptions.
>
> > Is there a reason you need to know about these status codes in your
> > controller?
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---