我想disable_with
在我的提交按钮中实现,所以我这样做:
我的观点:
= 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..."}
我的控制器:
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
我的模型:
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
它适用于小图像上传,但是当我上传更大的图像(大约 200 KB)时,我收到错误:
Errno::ENOTEMPTY at /user/update
Directory not empty @ dir_s_rmdir -
但是,如果我将其更改为正常的上传按钮,如下所示:
= f.button :submit, "Submit!", input_html: { id: "post-button", class: 'btn btn-primary'}
我上传任何文件都没有错误。我错过了什么?谢谢你的帮助。
更新:
失败后,我单击返回按钮(或返回并刷新)并尝试再次上传它,它可以工作。但是,如果我使用正常的页面流打开页面,它会失败。好奇怪:|
我为调用页面所做的工作:
%a{:href => account_path(@user)} Account
还有我的 routes.rb
get "/user/account(.:format)" => "user#edit", as: :account