0
我在使用載波在RoR上載圖像時遇到問題。每當我試着上傳文件我得到這個錯誤:載波多部分編碼錯誤
You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed. If this is a file upload, please check that your upload form is multipart encoded.
用戶#編輯:
= form_for(@user, multipart: true) do |f|
=f.file_field :avatar
= f.submit class: "btn btn-primary btn-block btn-lg"
users_controller:
def update
respond_to do |format|
if @user.update(user_params)
if params[:user][:avatar]
@user.avatar = params[:user][:avatar].tempfile.path
@user.save!
end
format.html { redirect_to @user, notice: 'User 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
我在user.rb
有mount_uploader :avatar, AvatarUploader
任何想法可能會出錯?