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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:24:36+00:00 2026-06-10T19:24:36+00:00

When ever a user types in any random string in the websites url ie

  • 0

When ever a user types in any random string in the websites url ie localhost:3000/rfgfgh or localhost:3000/gfgfgf/fhh it throws this random error.

I understand why it throws this error since I am checking if the user is contracter in the views and if they are display specific contracter code. I’m also using slugs to display contracter specific content. If the user goes to localhost:3000/contracter it checks for the slug contracter and then renders the page.

What are some solutions to remove this error? Is it possible to just redirect the user to the home page?

NoMethodError in Users#show

undefined method `contractor?' for nil:NilClass

1: <% if @user.contractor? %>
2:  <% title "#{@user.name}" %>
  • 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-10T19:24:37+00:00Added an answer on June 10, 2026 at 7:24 pm

    Based on the error you see, it means that you are calling something like @myuser.contracter?, where @myuser is nil.

    If the user isn’t in the database, it will not find the user, and put nil in the @myuser object.

    To redirect a user to the home page, simply check if the variable is nil in the controller, and redirect if necessary, eg:

    @myuser = User.find(params[:id]) # or params[:username]
    if @myuser.nil? # check if nil
      redirect_to root_url, :notice => "User does not exist!" # redirect to home page
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textfield where the user can type what ever he want into
I have the JavaScript code to fadein.fadeout the menu, when ever user hovers it.
So I'm building my first ever website with user accounts. What data should I
I wonder if it's ever possible to 'secure' wine; like for a user not
Ever since I created this Rails 3.2.3 project to use MiniTest, I have been
I keep getting this error ever so often when I launch the debugger to
If the user types in multiple characters when fgetc(STDIN) is called, another call to
In any programming environment,what ever the data type I am going to choose finally
This is driving me crazy. I'm not including any code because I want to
I'm a bit flabbergasted at this, so I'm wondering if any SOers have encountered

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.