title: error undefined method `avatar' for nil:NilClass
body: <p>hi i added carrierwave gem to my project and followed instruction but i am getting this error- <code>undefined method 'avatar' for nil:NilClass</code>. can anyone knows why i am not able to upload and view the uploaded file?</p>
  
  <pre><code>1.gem install carrierwave
  2.gem 'carrierwave', '~&gt; 2.0'
  3.rails generate uploader Avatar
  4.rails g migration add_avatar_to_project_sites avatar:string
  </code></pre>
  
  <p>project_sites_controller.rb</p>
  
  <pre><code>  def index
      @project_sites = current_user.project_sites.order("created_at DESC").paginate(page: params[:page], per_page: 10)
    end
    def create
      @project_site = current_user.project_sites.build(project_site_params)
  
      respond_to do |format|
        if @project_site.save
          format.html { redirect_to @project_site, notice: 'Attendance uploaded successfully' }
          format.json { render :show, status: :created, location: @project_site }
        else
          format.html { render :new }
          format.json { render json: @project_site.errors, status: :unprocessable_entity }
        end
      end
    end
  def project_site_params
    params.require(:project_site).permit(:name, :file, :attendance_month, avatar: [])
  end
  </code></pre>
  
  <p>project_site form.html.erb</p>
  
  <pre><code>&lt;div class="field"&gt;
    &lt;%= form.label :avatar %&gt;
    &lt;%= form.file_field :avatar %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>model project_site.rb</p>
  
  <pre><code>  mount_uploader :avatar, AvatarUploader
  </code></pre>
  
  <p>avatar_uploader.rb</p>
  
  <pre><code>class AvatarUploader &lt; CarrierWave::Uploader::Base
  
    include CarrierWave::MiniMagick
  
    storage :file
  
    def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
  end
  </code></pre>
  
  <p>project_site index.html.erb</p>
  
  <pre><code>&lt;%= image_tag @project_site.avatar.url %&gt;
  </code></pre>