종이 클립은 모든 종류의 파일 업로드를 허용하고 있으며 이해가되지 않습니다. 내 앱에서는 기본적으로 사용자가 등록 할 때 아바타를 업로드 할 필요는 없지만 등록 후에는 아바타를 업데이트 할 수 있습니다. 그리고 사용자는 아바타를 성공적으로 업데이트 할 수 있습니다. 이 모두가 잘 작동하지만, 검증이에서 발로되지 않은 User.rb에서 아래종이 클립 유효성 검사가 작동하지 않습니다.
검증 코드 :.
put 'updateavatar' => 'profile#updateavatar'
이 내입니다 :
has_attached_file :avatar, :styles => { :profile => "150x150#"}, :default_url => 'missing_:style.png'
validates_attachment :avatar, presence: true,
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png'], :message => 'must be a PNG, JPG, or JPEG'},
size: {less_than: 5.megabytes, :message => 'must be less than 5 megabytes'}
을 내 경로에서 나는 이것을 가지고 양식 :
<%= form_for current_user, :html => { :multipart => true }, :url => {:action => 'updateavatar'} do |form| %>
<%= form.file_field :avatar %>
<%= form.submit "Upload", class: "btn uploadbtn" %>
<% end %>
왜 이것이 작동하지 않을지 모르겠습니까? 사용자가 프로필을 업데이트하면 문자 그대로 모든 종류의 파일을 업로드 할 수 있습니다.
def updateavatar
if params[:user][:password].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
respond_to do |format|
if current_user.update_attribute(:avatar, params[:user][:avatar])
flash[:notice] = 'successfully updated.'
format.html { redirect_to profile_index_path }
else
format.html { render action: "index" }
end
end
end
별도의 유효성으로 validates_attachment_content_type 사용해보십시오. –
유감스럽게도 유효성 검사는 여전히 건너 뛰고 있습니다. –
http://stackoverflow.com/a/12686796/1251349 –