title: Upload base64 Image with Paperclip - Rails 4
body: <p>I am relatively new to Rails and would appreciate any help.</p>
  
  <p>My website accepts a signature image in base64 format and I am trying to use a Paperclip adaptor to decode the image and save it to my <code>form</code> model as the <code>:signature</code> attribute. I am using the advice given <a href="https://stackoverflow.com/a/28036282/4822174">here</a> (and <a href="https://gist.github.com/WizardOfOgz/1012107" rel="nofollow noreferrer">here</a>) which advises to use the following code:</p>
  
  <p>In model:</p>
  
  <pre><code>class Thing
      has_attached_file :image
  </code></pre>
  
  <p>In controller:</p>
  
  <pre><code>def create
    image = Paperclip.io_adapters.for(params[:thumbnail_data]) 
    image.original_filename = "something.gif"
    Thing.create!(image: image)
    ...
  end
  </code></pre>
  
  <p>My assumption is that <code>Thing.create!</code> is setting the value of Paperclip's model attribute <code>:image</code> to be the value of the <code>image</code> variable whilst creating and saving a new Thing object. I tried to implement the same code in my <code>FormsController</code> (create action) before <code>@form.save</code>, but am receiving this error:</p>
  
  <pre><code>undefined method `before_image_post_process' for #&lt;Class:0x007f94a2a26de8&gt;
  </code></pre>
  
  <p>My <code>FormsController</code>:</p>
  
  <pre><code>class FormsController &lt; ApplicationController
    before_action :logged_in_user
    before_action :admin_user, only: :destroy
  
    def index
      @forms = Form.all #paginate
    end
  
    def show
      @form = Form.find(params[:id])
    end
  
    def new
      @form = Form.new
    end
  
    def create
      @form = Form.new(form_params)
  
      # Paperclip adaptor 
      signature = Paperclip.io_adapters.for(params[:base64])
      signature.original_filename = "something.png"
  
      # Attempt to submit image through Paperclip
      @form.signature = signature
  
      if @form.save
        flash[:success] = "The form has been successfully created!"
        redirect_to @form
      else
        render 'new'
      end
    end
  
    def edit
      @form = Form.find(params[:id])
    end
  
    def update
      @form = Form.find(params[:id])
      if @form.update_attributes(form_params)
        flash[:success] = "Form has been updated!"
        redirect_to @form
      else
        render 'edit'
      end
    end
  
    def destroy
      Form.find(params[:id]).destroy
      flash[:success] = "Form deleted"
      redirect_to forms_path
    end
  
    private
  
    def form_params
      params.require(:form).permit(:first_name, :last_name, :email, :phone, :address, :member_type, :base64)
    end
  end
  </code></pre>
  
  <p>This is my <code>Form</code> model:</p>
  
  <pre><code>class Form &lt; ActiveRecord::Base
  
    has_attached_file :signature
    validates_attachment_content_type :image, :content_type =&gt;     ["image/jpg", "image/jpeg", "image/png", "image/gif"]
  
   end
  </code></pre>