Paperclip позволяет загружать любые файлы, и я не понимаю. В моем приложении по умолчанию пользователям не нужно загружать аватары, когда они регистрируются, но они могут обновлять свой аватар после регистрации. И пользователь может успешно обновить свой аватар. Это все работает отлично, но валидация не ногами вПодтверждения скрепки не работают
проверочный код ниже в User.rb:.
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'}
В моих маршрутов я это:
put 'updateavatar' => 'profile#updateavatar'
Это мой форма:
<%= 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 –