title: Paperclip extension error
body: <p>I use <a href="https://github.com/thoughtbot/paperclip" rel="nofollow">this tutorial</a> but can not upload image with paperclip, it gives "Avatar has an extension that does not match its contents" error.</p>
  
  <p>I am sure ImageMagick is installed and worked properly. </p>
  
  <p><strong>form:</strong></p>
  
  <pre><code>&lt;%= form_for @user, :url =&gt; users_path, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
    &lt;% if @user.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@user.errors.count, "error") %&gt; prohibited this user from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @user.errors.full_messages.each do |message| %&gt;
          &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :avatar %&gt;&lt;br&gt;
      &lt;%= f.file_field :avatar %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>user_controller</strong></p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_action :set_user, only: [:show, :edit, :update, :destroy]
    # GET /users
    # GET /users.json
    def index
      @users = User.all
    end
    # GET /users/1
    # GET /users/1.json
    def show
    end
    # GET /users/new
    def new
      @user = User.new
    end
    # GET /users/1/edit
    def edit
    end
    # POST /users
    # POST /users.json
    def create
      @user = User.new(user_params)
      respond_to do |format|
        if @user.save
          format.html { redirect_to @user, notice: 'User was successfully created.' }
          format.json { render :show, status: :created, location: @user }
        else
          format.html { render :new }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
    # PATCH/PUT /users/1
    # PATCH/PUT /users/1.json
    def update
      respond_to do |format|
        if @user.update(user_params)
          format.html { redirect_to @user, notice: 'User was successfully updated.' }
          format.json { render :show, status: :ok, location: @user }
        else
          format.html { render :edit }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
    # DELETE /users/1
    # DELETE /users/1.json
    def destroy
      @user.destroy
      respond_to do |format|
        format.html { redirect_to users_url }
        format.json { head :no_content }
      end
    end
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_user
        @user = User.find(params[:id])
      end
      # Never trust parameters from the scary internet, only allow the white list through.
      def user_params
        params.require(:user).permit(:avatar)
      end
  end
  </code></pre>
  
  <p><strong>user.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_attached_file :avatar, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;" }, :default_url =&gt; "/images/:style/missing.png"
    validates_attachment_content_type :avatar, :content_type =&gt; /\Aimage\/.*\Z/
  end
  </code></pre>