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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:10:25+00:00 2026-05-24T12:10:25+00:00

I have a few local variables in my partials which may or may not

  • 0

I have a few local variables in my partials which may or may not be passed by the template that renders them, for instance: on_question_page. If I’m on the page I pass it as true but elsewhere I skip it.

The problem is that I can’t reference that variable directly because in the places it isn’t defined it throws an error.

This means that I end up with a lot of code like this at the top of my partials:

on_question_page = defined?(on_question_page) ? on_question_page : false

Messy. Is there a cleaner way to access these optional variables?

  • 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-24T12:10:26+00:00Added an answer on May 24, 2026 at 12:10 pm

    You can use on_question_page ||= false to assign false if on_question_page is undefined or false or nil, that is, something which evaluates to false when tested with boolean operators.

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

Sidebar

Related Questions

I have a few local variables and I want to divide them all divide
I accidentally deleted a few files from my local git repo. I have not
I have a local Git repository I've been developing under for a few days:
I have few node types and some of them have an extra field is
I have few tabs and I need to way to access textboxes on them
I have few different applications among which I'd like to share a C# enum.
In my Gradle script (version 0.8), I have a local ivy repository which I
I have a class which contains a few boost::numeric::ublas::matrix's within it. I would like
We have a vSphere 5 Hypervisor that runs few Windows XP/Vista/7 virtual machines with
I have been thinking a little about environment variables and have a few questions/observations.

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.