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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:01:26+00:00 2026-06-11T16:01:26+00:00

I had my rails applications running OmniAuth-identity, saving users at Users model. Accesing users

  • 0

I had my rails applications running OmniAuth-identity, saving users at “Users” model.
Accesing users required pointing to:

0.0.0.0:3000/users/:id

but I wanted to get there by just typing the unique name of the user, like facebook or twitter:

0.0.0.0:3000/username

So I created a globed route:

match "/*id" => "users#show"

and modified the users controller show method to find by name instead of ID, depending on the paramter passed:

def show
    if params[:id].is_a?(String)
      @user = User.find_by_name(params[:id])
    else
      @user = User.find(params[:id])
    end
    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user }
    end
  end

Routing works, If i go to

0.0.0.0:3000/username

It shows succesfully the user info.
But loging out or finding the user like old routes are not working.. (even with the conditional I added to the controller checking if String||Int.

When doing this things I get:

NoMethodError in Users#show

Showing /home/juanchi/Dropbox/GitHub/RSandBox/app/views/users/show.html.erb where line #5 raised:

undefined method `provider' for nil:NilClass
Extracted source (around line #5):

2: 
3: <p>
4:   <b>Provider:</b>
5:   <%= @user.provider %>
6: </p>
7: 
8: <p>
Rails.root: /home/juanchi/Dropbox/GitHub/RSandBox

Application Trace | Framework Trace | Full Trace
app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb___448583227_80374500'
app/controllers/users_controller.rb:22:in `show'
Request

Parameters:

{"id"=>"logout"}
Show session dump

Show env dump

Response

Headers:

None

It fails on getting the info at show method of users controller. But when using the new route it goes fine… So what is it missing?

How can I support my new routing rule and the old one at the same time?

And what does that route has to do with the user loggin out method?

When logging out it calls sessions#detroy method:

def destroy
    session[:user_id] = nil
    redirect_to root_url, :notice => "Goodbye!"
  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-11T16:01:27+00:00Added an answer on June 11, 2026 at 4:01 pm

    I’m not sure if I got the idea but I think that you don’t need to use globbed routes.

    You can use something like this:

    get "users/:id" => "users#show"
    get ":username" => "users#show"
    

    And in your action you can check existence of parameter:

    def show
      if params[:id].present?
        @user = User.find(params[:id])
      elsif params[:username].present?
        @user = User.find_by_name(params[:username])
      end
    end
    

    To check type of the parameter as you have in your code doesn’t make sense as it’s always String (or NilClass if it’s nil).

    And there is also one important thing – routes are ordered so you have to have your get ":username" ... somewhere at the end of the routing table to prevent conflicts with standard actions like /logout, /login, etc.

    Actually it’s not simple to eliminate those conflicts completely – imagine that you have user that chose the name “logout”. So you have to add another logic that prevents such names for users.

    Update: I forgot to explain why I think that globbing is not necessary – you need globbing to catch things like “foo/bar”, “something/nice/in/rails” with one rule match "*xxx"

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

Sidebar

Related Questions

Trying to generate Rails API documentation, but running into errors: $ rake doc:rails rake
I had the official authlogic plugin running perfectly on Rails 2.3.5. I converted my
What behavior have you had to implement in your Rails applications that you feel
I had model Event and User (Devise gem) in my ruby on rails application.
I'm running ruby 1.9.2 with rails (3.0.7) on windows 7. Had a hard time
I just upgraded my Leopard system to Snow. I had a Rails application with
I have had this problem w/ two seperate WYSWYG editors in my rails application
I had ruby 1.8.7 and rails 2.3.5 installed on my machine.I had install RVM
I had this app using 1.9.2 and rails 3.2 and today I changed the
I had the gmaps4rails gem version 1.4.5 working nicely on my Rails 3.2.2 app.

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.