Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip validations are not working
    primarykey
    data
    text
    <p>Paperclip is allowing any kind of file upload, and I don't understand. In my app, by default, Users don't have to upload avatars when they register, but they may update their avatar after registration. And the user is able to successfully update their avatar. This all works fine, but the validations are not kicking in.</p> <p>Validation code below in the User.rb:</p> <pre><code>has_attached_file :avatar, :styles =&gt; { :profile =&gt; "150x150#"}, :default_url =&gt; 'missing_:style.png' validates_attachment :avatar, presence: true, content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png'], :message =&gt; 'must be a PNG, JPG, or JPEG'}, size: {less_than: 5.megabytes, :message =&gt; 'must be less than 5 megabytes'} </code></pre> <p>In my routes I have this:</p> <pre><code>put 'updateavatar' =&gt; 'profile#updateavatar' </code></pre> <p>This is my form:</p> <pre><code>&lt;%= form_for current_user, :html =&gt; { :multipart =&gt; true }, :url =&gt; {:action =&gt; 'updateavatar'} do |form| %&gt; &lt;%= form.file_field :avatar %&gt; &lt;%= form.submit "Upload", class: "btn uploadbtn" %&gt; &lt;% end %&gt; </code></pre> <p>I don't know why this wouldn't work? It's literally allowing any kind of file to be uploaded when the user updates their profile.</p> <p>In my profile controller I have this:</p> <pre><code> 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload