Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:59:17+00:00 2026-06-07T14:59:17+00:00

Why I cannot rescue anything in the following method? def get_things begin things= @member.things.where(id>?,params[:id])

  • 0

Why I cannot rescue anything in the following method?

def get_things
  begin
    things= @member.things.where("id>?",params[:id])
  rescue ActiveRecord::StatementInvalid
    render( inline: "RESCUED ActiveRecord::StatementInvalid" )
    return
  rescue
    render( inline: "RESCUED something" )
    return
  end
  render( inline: "#{things.first.title}" )
end

When called with a valid id, it works:

$  curl -vd "id=3" http://localhost:3000/get_things

but if I pass a wrong one, such as:

$  curl -vd "id=3,0" http://localhost:3000/get_things
$  curl -vd "id='3'" http://localhost:3000/get_things

the exception isn’t rescued:

< HTTP/1.1 500 Internal Server Error
<h1>
  ActiveRecord::StatementInvalid
    in ApplicationController#get_things
</h1>
<pre>PG::Error: ERROR:  invalid input syntax for integer: &quot;'3'&quot;

Only when rendering happens inside begin/rescue block

def get_things
  begin
    things= @member.things.where("id>?",params[:id])
    render( inline: "#{things.first.title}" )
  rescue ActiveRecord::StatementInvalid
    render( inline: "RESCUED ActiveRecord::StatementInvalid" )
    return
  end
end

it works as expected:

$ curl -vd "id='3'" http://localhost:3000/get_things
  < HTTP/1.1 200 OK
  RESCUED ActiveRecord::StatementInvalid
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:59:21+00:00Added an answer on June 7, 2026 at 2:59 pm

    As far as I know, the things in your case will be a class containg information on your query, but the query won’t be executed till you try to acces an element based on the query (like things.first).

    things= @member.things.where("id>?",params[:id]) # query not run
    things= things.order("id desc") # still not run
    things.first.title # now the query runs, the statement can be invalid
    

    This is why it can’t be rescued, because in your render line, where the exception occurs, not in the creation of the things.

    This should be okay:

    def get_things
      begin
        things= @member.things.where("id>?",params[:id])
        thing_title = things.first.title
      rescue ActiveRecord::StatementInvalid
        render( inline: "RESCUED ActiveRecord::StatementInvalid" )
        return
      rescue
        render( inline: "RESCUED something" )
        return
      end
      render( inline: "#{thing_title}" )
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot wrap my brain around the following thing ... and I hope there's
Cannot validate this method because the domain mapping for the return type (XXXProxy) could
Cannot explain what is going on the following program. GetType is returning the type
Cannot find method in silverlight VisualTreeHelper.GetDescendantBounds(item). Do you know any analogs?
I am trying to handle an exception caused by this following code: begin reader
I have the following method to create a new Connection object. It will open
Cannot work out how to get the following menu to display correctly in IE6,
Cannot find out why this is not working?: def frequencies(counts): total = sum(counts) frequencies
Cannot seem to loop through the XElement and build a datatable. My XElement will
Cannot dump Stack Overflow XML file into SQL Server 2008. Could you please explain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.