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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:38:58+00:00 2026-06-10T15:38:58+00:00

Using below search method Im unable to check if the params exists. It always

  • 0

Using below search method Im unable to check if the params exists.
It always throws an NoMethodError (undefined method `[]’ for nil:NilClass):

The if params[‘/people’][:age_from].present? && params[‘/people’][:age_to].present? if statement and the one for gender seems to totally fail and have no idea why 🙁

   def self.search(params)

    puts params

    tire.search(load: true, page: params[:page], per_page: 20) do
      query do
        boolean do
          should { range :age, {gte: params['/people'][:age_from], lte: params['/people'][:age_to]} } if params['/people'][:age_from].present? && params['/people'][:age_to].present? 
          should { string 'gender:male' } if params['/people'][:gender].present && params['/people'][:gender] == "male" 
        end
      end
      to_curl
    end
  end

VERY messy:
but this seems to work

  def self.search(params)
    if params['people']
      tire.search(load: true, page: params[:page], per_page: 20) do
        query do
          boolean do
            should { range :age, {gte: params['people'][:age_from], lte: params['people'][:age_to]} }
            should { string 'gender:male' } if params['people'][:gender] == "male"
            should { string 'gender:female' } if params['people'][:gender] == "female"
          end
        end
        to_curl
      end
    else
      if Rails.env == "development"
        @profiles = Profile.where('status IS NOT NULL').page(params[:page]).order("id").per_page(50)
      else
        @profiles = Profile.where("user_id != ?", current_user.id).where('status IS NOT NULL').order("id").page(params[:page]).per_page(40)
      end
    end

  end
  • 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-10T15:39:00+00:00Added an answer on June 10, 2026 at 3:39 pm

    That is because params['/people'] is nil, and nil[] returns exactly the error you are getting.

    You should also check for the existence of the first part in the hash as in:

    if params['/people'] && params['/people'][:gender].present && params['/people'][:gender] == "male"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search method below using linq, my search citeria is based on
I am using the method below to search for a string in a web
I'm using below code to check some form fields and render datatable table on
I am using below method for validating that one of radio button must be
I'm looking for a way to write a search and replace method using W3C
I know how to do a search using the Outlook.AdvancedSearch() method. What I want
I am using recursive method to create a Binary Search Tree. My objective is
Am using below third party API in my project development http://undesigned.org.za/2007/10/22/amazon-s3-php-class I have done
I am using below code to upload excel and INSERT in mysql in php
I am using below code to get profile image of friends using Resfb. I

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.