title: NoMethodError in Rails method using has_one association
body: <p>Here is my code:</p>
  
  <p>// in swimmer.rb (model):</p>
  
  <pre><code>    belongs_to :user
  </code></pre>
  
  <p>// in user.rb (model):</p>
  
  <pre><code>    has_one :swimmer, :dependent =&gt; :destroy
      accepts_nested_attributes_for :swimmer, :allow_destroy =&gt; true   
      attr_accessible :swimmer_attributes
  </code></pre>
  
  <p>// in swimmers_controller.rb:</p>
  
  <pre><code>  def profile
      @swimmer = Swimmer.find_by_user_id(current_user)
      @swimmer_nickname = @swimmer.nickname
      @swimmer_gender = @swimmer.gender
      @title = "Swimmer Profile for #{@current_user.email}"
    end
  </code></pre>
  
  <p>// in profile.html.erb (in swimmers views folder)</p>
  
  <pre><code>   &lt;% if @swimmer %&gt;
       &lt;h3&gt;&lt;%= @title %&gt;&lt;/h3&gt;
       &lt;p&gt;Nickname: &lt;%= @swimmer_nickname %&gt;&lt;/p&gt;
       &lt;p&gt;Gender: &lt;%= @swimmer_gender %&gt;&lt;/p&gt;
     &lt;% else %&gt;
       &lt;h3&gt;No Swimmer Profile for&lt;%= current_user.email %&gt;&lt;/h3&gt;
     &lt;% end %&gt;
  </code></pre>
  
  <p>If a swimmer object has a user_id that matches the @swimmer instance variable in the swimmers#controller method, because there is a logged in user (using the Devise gem) and a swimmer has been created for that user, then the profile view works as intended. If not, the page shows an error:</p>
  
  <pre><code>   NoMethodError (undefined method `nickname' for nil:NilClass):
       app/controllers/swimmers_controller.rb:66:in `profile'
  </code></pre>
  
  <p>But since the profile view has an if/else conditional, I want the lack of the swimmer object associated with the logged in user to force the view to show the else content. Apparently, the "Swimmer.find_by_user_id(current_user)" method is creating a nil object in the NilClass. How do I get it so that it doesn't create anything and thereby brings up the else conditional?</p>
  
  <p>Repo is at <a href="https://github.com/drollwit/vst2/tree/ver2" rel="nofollow">https://github.com/drollwit/vst2/tree/ver2</a>. This is an exercise, not a real project. There is probably an easy answer here but I can't figure it out (still learning Rails basics). Any help would be appreciated.</p>