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 6019833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:28:42+00:00 2026-05-23T03:28:42+00:00

Should be an easy question, but I couldn’t find anything on SO about it,

  • 0

Should be an easy question, but I couldn’t find anything on SO about it, so I’m just throwing mine out there:

thing_i_use = Thing.find(params[:id])

As it stands, in the event that there is no Thing with params[:id], the website defaults to a development page with stack tracing, etc., claiming that there is no thing with ID=etc.

What I’m wondering is how to test against this such that thing_i_use is nil if the params[:id] doesn’t exist, or is the object itself. Basically, using the non-existence of the object in my logic later on in the code.

  • 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-05-23T03:28:43+00:00Added an answer on May 23, 2026 at 3:28 am

    Replace:

    thing_i_use = Thing.find(params[:id])
    

    With:

    thing_i_use = Thing.find_by_id(params[:id])
    

    The latest won’t spit any error if id doesn’t exist or is nil.

    thing_i_use will only be nil, this will be the only test to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it seems like it should be dead easy, but i couldn't find anything in
So this should be a real easy question but I can't seem to find
This should be easy for many of you, but for me it's just another
This should be easy, but I'm not sure how to best go about it.
This should be an easy question - but I'm having a hard time figuring
OK, this feels like a question that should be easy to answer, but as
It should be an easy question , I am building a site under IIS
Should be a quick and easy question. Does System.Drawing.Graphics.DrawImage() or Image.Save() by default make
My question is quite simple and with the SharpSvn Api, it should be easy
This should a quick question for some easy rep. I'm doing some PHP Website

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.