Forum: Ruby on Rails rescue_from for NoMethodError

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.
shahroon ali (Guest)
on 2009-02-10 14:15
(Received via mailing list)
Hi everyone,
                    I was just trying to catch some exceptions in my
app,
for "Record Not Found" I used this
in my application.rb file
  rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
  rescue_from ActionController::NoMethodError, :with => :show_error

private

  def record_not_found
    render :text => "404 Not Found", :status => 404
  end
  def show_error(exception)
    render :text => exception.message;
  end


and was quite successful but for "NoMethodError" I am trying the same
but It
isn't working at all. Can anybody help me?
Thanks in advance,
Shahroon
Frederick C. (Guest)
on 2009-02-10 18:02
(Received via mailing list)
On 10 Feb 2009, at 12:14, shahroon ali wrote:

>     render :text => "404 Not Found", :status => 404
>   end
>   def show_error(exception)
>     render :text => exception.message;
>   end
>
>
> and was quite successful but for "NoMethodError" I am trying the
> same but It isn't working at all. Can anybody help me?

Because ActionController::NoMethodError doesn't exist. It's just plain
NoMethodError (possibly ::NoMethodError but I don't think that's
needed here)

Fred
shahroon ali (Guest)
on 2009-02-11 09:03
(Received via mailing list)
Oh Yeah my mistake it was
rescue_from NoMethodError, :with => :show_error
but now I am following this procedure but no success in "NoMethodError"

  rescue_from  NameError, :with => :handle_exceptions
  rescue_from  NoMethodError, :with => :handle_exceptions
  rescue_from  ActiveRecord::Rollback, :with => :handle_exceptions
  rescue_from  ActiveRecord::StatementInvalid, :with =>
:handle_exceptions
  rescue_from  ActiveRecord::RecordNotFound, :with => :handle_exceptions
  rescue_from  ActionController::UnknownAction, :with =>
:handle_exceptions
  rescue_from  ActiveRecord::RecordNotFound, :with => :handle_exceptions
  rescue_from  ActiveRecord::StaleObjectError, :with =>
:handle_exceptions
  rescue_from  ActiveRecord::RecordInvalid, :with => :handle_exceptions
  rescue_from  ActiveRecord::RecordNotSaved, :with => :handle_exceptions
  rescue_from  ActionController::MethodNotAllowed, :with =>
:handle_exceptions
  rescue_from  ActionController::MethodNotAllowed, :with =>
:handle_exceptions
  rescue_from  ActionController::InvalidAuthenticityToken, :with =>
:handle_exceptions

private

  def handle_exceptions
    render :action => '500.html',:text => 'This is an error', :status =>
500
  end

Any ideas how to solve this problem?

Shahroon

On Tue, Feb 10, 2009 at 9:02 PM, Frederick C. <
This topic is locked and can not be replied to.