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

  • Home
  • SEARCH
  • 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 6156097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:33:05+00:00 2026-05-23T20:33:05+00:00

I frequently find myself having to do an extra nil check (to avoid throwing

  • 0

I frequently find myself having to do an extra nil check (to avoid throwing an ‘undefined for nil’ error) that I’m pretty sure is unnecessary.

In one common example, when looking at optional url params, e.g. which might or might not exist, I like them to be case insensitive (if they exist).

for example one of my controller methods allows (doesn’t require) &showdate=true and I like to make it user friendly by not caring about true vs TRUE vs True.

I could just say

@showdate = params[:showdate] == "true"

but that assumes lower case.

If I do this:

@showdate = params[:showdate].lower == "true"

it of course throws an unwanted error if showdate is missing from the url becasue nil.lower throws an error.

So I end up doing something like this LOTS of time in my code:

if params[:showdate] 
  @showdate = params[:showdate].lower == "true"
else
  @showdate = false (or maybe nil)

I know there’s a Better Way, just don’t know what it is. Any help would be appreciated.

  • 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-23T20:33:07+00:00Added an answer on May 23, 2026 at 8:33 pm
    @showdate = params[:showdate].to_s.downcase == "true"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I frequently find myself writing utility classes that can be re-used throughout my projects.
As part of my current role, I frequently find myself having to work with
I frequently find myself using setlocal within cmd.exe to avoid polluting the environment variable
I frequently find myself doing this: !(val).nil? My code would be prettier if there
I frequently find myself having a need to create a class as a container
I frequently find myself writing code like this: List<int> list = new List<int> {
I frequently find myself creating classes which use this form (A): abstract class Animal
Regarding the classic test pattern of Arrange-Act-Assert , I frequently find myself adding a
I find that I frequently end up writing a function that I always call
I find myself writing SQL code (queries or stored procs) to solve problems that

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.