title: undefined method `name' for nil:NilClass
body: <p>I am trying to find users in "show" action of my "Users" controller using email. Where i am getting this error.</p>
  
  <pre><code>NoMethodError in UsersController#show
    undefined method `name' for nil:NilClass
  </code></pre>
  
  <p>Now i am using singular resource routes as without singular resource i was getting error like</p>
  
  <pre><code>Routing Error
   No route matches {:action=&gt;"show", :controller=&gt;"users", :id=&gt;#&lt;User name: "sandip", email: "sandip@example.com", address: nil, encrypted_password: "605b20529364629b7668d55006310536", created_at: "2011-10-07 04:23:23", updated_at: "2011-10-07 04:23:23"&gt;}
  </code></pre>
  
  <p>Now my routes.rb file looks like this.</p>
  
  <pre><code>Demo::Application.routes.draw do
    resource :user
    resources :sessions, :only =&gt; [:new, :create, :destroy]
  
    match '/signout', :to =&gt; 'sessions#destroy'
    match 'user/:email', :to =&gt; 'users#show'
    root :to =&gt; "sessions#new"
  end
  </code></pre>
  
  <p>With this routes the "Routing Error" is gone but a new "NoMethodError" error has come up.</p>
  
  <p>My user controller( only question related part)</p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
    def show      
      @user = User.find_by_email(params[:email]) if params[:email].present?
      @title = @user.name
    end
  end
  </code></pre>
  
  <p>In order to find user using email i have added a method in my user model.</p>
  
  <p>My user model(only question related part)</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
     def to_param  # overridden
       "#{email}"
     end
  end
  </code></pre>
  
  <p>Now when a user Sign In, the url on the browser comes like this.</p>
  
  <pre><code>http://localhost:3000/user?format=sandip%40example.com
  </code></pre>
  
  <p>and i get "NoMethodError" error.
  But when i manually change "format" to "email" on the url , everything works fine.</p>
  
  <pre><code>http://localhost:3000/user?email=sandip%40example.com 
  </code></pre>
  
  <p>How can i get "email" instead of "format" on the url ? Can somebody help please. </p>