title: Hartl's rails tutorial ch11: Why is my account_activation mailer template preview not working?
body: <p>I am on ch11 of Hartl's rails tutorial, section 11.2.1 Mailer Templates, The preview for the password reset mailer works fine but the account_activation preview does not. the error actually changed even though i didn't make any changes to the code, which was confusing. However the error that I am currently receiving is </p>
  
  <pre><code>NoMethodError in Rails::Mailers#preview
  
  Showing /home/ubuntu/workspace/sample_app/app/views/user_mailer/account_activation.html.erb where line #3 raised:
  
  undefined method `name' for nil:NilClass
  
  Extracted source (around line #3)
  
  &lt;h1&gt;Sample App&lt;/h1&gt;
  
  &lt;p&gt;Hi &lt;%=@user.name %&gt;,&lt;/p&gt;
  
  &lt;p&gt;
  Welcome to the Sample App! Click on the link below to activate your account:
  </code></pre>
  
  <p>here is my user_mailer.rb</p>
  
  <pre><code>class UserMailer &lt; ApplicationMailer
  
    def account_activation(user)
      @user = user
      mail to: user.email, subject: "Account activation"
    end
  
    def account_activation
      @greeting = "Hi"
  
      mail to: "to@example.org"
    end
  
    def password_reset
      @greeting = "Hi"
  
      mail to: "to@example.org"
    end
  end
  </code></pre>
  
  <p>account_activations_controller.rb (no code has been specified so far in the tutorial)</p>
  
  <pre><code>class AccountActivationsController &lt; ApplicationController
  end
  </code></pre>
  
  <p>and the source of the error account_activation.html.erb</p>
  
  <pre><code>&lt;h1&gt;Sample App&lt;/h1&gt;
  
  &lt;p&gt;Hi &lt;%=@user.name %&gt;,&lt;/p&gt;
  
  &lt;p&gt;
  Welcome to the Sample App! Click on the link below to activate your account:
  &lt;/p&gt;
  
  &lt;%= link_to "Activate", edit_account_activation_url(@user.activation_token,
                                                      email: @user.email) %&gt;
  </code></pre>
  
  <p>it seems to not be recognising the name of the user. why could this be? (Note: all code is copied from the tutorial so i am at a loss as to the reason for the error)
  thanks.</p>
  
  <p>EDIT:As per the comment there wer indeed 2 account_activation methods. i have deleted the second one and kept the first.  Now the error has changed to an argument error.</p>
  
  <pre><code>ArgumentError in Rails::MailersController#preview 
  wrong number of arguments (given 0, expected 1)
  
    def account_activation(user)
      @user = user
      mail to: user.email, subject: "Account activation"
    end
  </code></pre>
  
  <p>This method seems to be used in the following file without an argument.</p>
  
  <p>/sample_app/test/mailers/previews/user_mailer_preview.rb</p>
  
  <pre><code>class UserMailerPreview &lt; ActionMailer::Preview
  
    # Preview this email at http://localhost:3000/rails/mailers/user_mailer/account_activation
    def account_activation
      user = User.first
      user.activation_token = User.new_token
      UserMailer.account_activation(user)
      UserMailer.account_activation
    end
  
    # Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset
    def password_reset
      UserMailer.password_reset
    end
  
  end
  </code></pre>