I want to implement disable_with in my submit button so I do it like this:
My view:
= simple_form_for(@user, :url => update_profile_path, :method => :patch) do |f|
   = f.input :avatar 
   = f.button :button, "Update".html_safe, data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> Saving..."}
My Controller:
def edit
    @user = User.find_or_initialize_by(id: current_user.id)
end
def update_profile
    @user = User.where(id: current_user.id)
    respond_to do |format|
        if @user.update(current_user.id, user_params)
            format.html { redirect_to root_path, notice: 'Profile was successfully updated.' }
            format.json { head :no_content }
        else
            format.html { render action: 'edit' }
            format.json { render json: @user.errors, status: :unprocessable_entity }
        end
    end
end
My model:
class User < ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
        :recoverable, :rememberable, :trackable, :validatable
    # Validations
    validates :name, presence: true
    geocoded_by :full_address
    after_validation :geocode
    has_many :posts, dependent: :destroy
    has_many :comments, dependent: :destroy
    # Paperclip
    has_attached_file :avatar, :styles => { :thumb => "100x100>" },
        :default_url => "users/avatars/missing.png"
    validates_attachment_content_type :avatar, :content_type => /\Aimage/
    validates_attachment_file_name :avatar, :matches => [/png\Z/, /jpe?g\Z/]
end
It works fine with small image upload, but when I upload a bigger image (around 200KB) I get error:
Errno::ENOTEMPTY at /user/update
Directory not empty @ dir_s_rmdir -
However, if I change it to normal upload button like this:
= f.button :submit, "Submit!", input_html: { id: "post-button", class: 'btn btn-primary'}
I have no error uploading any files. Did I miss something? Thanks for your help.
Update:
After it fails, I click the back button (or back and refresh) and try to upload it again and it works. But if I open the page using the normal page flow it fails. So strange :|
What I do for calling the page:
%a{:href => account_path(@user)} Account
And my routes.rb
get "/user/account(.:format)" => "user#edit", as: :account