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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:08:06+00:00 2026-06-07T20:08:06+00:00

I’m working through the Michael Hartl Tutorial and am having trouble getting sign-outs to

  • 0

I’m working through the Michael Hartl Tutorial and am having trouble getting sign-outs to work.

Instead of ID’ing by email, I’m working by username.

Signing up and singing in both work fine, but my sign out causes an error:

ActiveRecord::RecordNotFound in UsersController#show

Couldn't find User with username = signout

app/controllers/users_controller.rb:9:in `show'

Why is it looking in the users_controller, in the show method? Why is it calling that? It should be calling sessions controller’s delete method, right?

The offending line 9 is:

  8  def show
  9     @user = User.find_by_username!(params[:username])
  10 end

I don’t understand where the parameters are getting passed in (where and to what) that cause it to think “signout” == the username, rather than finding by username and routing to session#destroy. How can I diagnose this? What can I type in the Rails console to find out what is currently contained in params?

Update:

I thought the solution below worked when I tried it immediately, but the problem had just changed from one error message to another. I have moved the routes around as suggested and am still getting

Request Parameters: {"username"=>"signout"} just this time it’s located in my

`Users#show model: users/show.html.erb where line #1 raised: 

undefined method username' for nil:NilClass 

Extracted source (around line #1): 

1: <\h2><%= @user.username %><\/h2> 
2: 
3: <!-- 
4:`

And here are the contents of my routes.rb file:

   match 'signup', to: 'users#new'
   match 'signin', to: 'sessions#new'
   match 'signout', to: 'sessions#destroy', via: 'delete'

   resources :sessions, only: [:new, :create, :destroy]

   match "/:username"  => "users#show", via: "get"
   resources :users
  • 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-07T20:08:09+00:00Added an answer on June 7, 2026 at 8:08 pm

    I’m guessing you have a route which looks like this:

    get "/users/signout" => "sessions#destroy"
    

    Before this, you probably have a line that looks like this:

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

    The problem is that routing to /users/signout will match /users/:username, and send your request to the show action of the UsersController, setting params[:username] to "signout". You are then calling User.find_by_username!("signout")

    You need to put your /users/signout route above your /users/:username line so that it is matched before the /users/:username route. Remember that Rails stops trying to find a matching route at the first one which can match a request URI. Your more generic wild-card routes must appear after more specific routes that have the potential to overlap.


    RE: Your update

    Your signout route requires an HTTP DELETE request, which rails simulates via a POST request with a _method=delete parameter.

    In order to match this route, you need to use a form or a button_to to issue a DELETE request:

    button_to "Signout", signout_path, :method => :delete
    

    Destroying sessions is (in my opinion) a special case where you should accept any type of HTTP request. Users should be able to type /logout or /signout into their address bar and destroy their session via a GET request. I strongly suggest your remove the via: :delete and use the following:

    match 'signout' => 'sessions#destroy'
    

    Conversely, you’re being too lenient with your signup and signin routes, which should use GET and POST requests specifically, and route to new and create actions rather than to the same action.

    get 'signup' => 'users#new'
    post 'signin' => 'sessions#create'
    

    What can I type in the Rails console to find out what is currently contained in params?

    Nothing. You cannot inspect the params hash via the Rails console, because there is no request. You can inspect in your log files by adding logger.info(params.inspect), or in the browser by raising it as an error message: raise params.inspect.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.