Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating avatar on Ruby on Rails with paperclip
    primarykey
    data
    text
    <p>I've looked around and I cannot figure out why this is working. I allow users to sign up, without needing them to upload avatars at first. However, if they wish, they can upload avatars after signing up. I allow them to edit their avatar in a "profiles" controller, not in the user controller. However, the avatar won't update. I'm using devise for the users. Code below</p> <pre><code>&lt;%= form_for edit_user_path(current_user.id), :html =&gt; { :multipart =&gt; true } do |form| %&gt; &lt;%= form.file_field :avatar %&gt; &lt;%= form.submit "upload" %&gt; &lt;% end %&gt; </code></pre> <p>And in the Users controller, I have this:</p> <pre><code>def edit @user = User.find(params[:id]) @user.update_attribute(:avatar, params[:user][:avatar]) end </code></pre> <p>And in the user model, I have this</p> <pre><code>has_attached_file :avatar, :styles =&gt; { :show =&gt; "150x150#" }, :default_url =&gt; 'missing_:style.png' </code></pre> <p>The avatar does not update or save. I'm not sure why.</p> <p>Update with new form code:</p> <pre><code>&lt;%= form_for current_user, :url =&gt; {:action =&gt; 'update'}, :html =&gt; { :multipart =&gt; true } do |form| %&gt; &lt;%= form.file_field :avatar %&gt; &lt;%= form.submit "upload" %&gt; &lt;% end %&gt; </code></pre> <p>In the profiles controller, I have this: </p> <pre><code>def update @user = User.find(params[:id]) @user.update_attribute(:avatar, params[:user][:avatar]) end </code></pre> <p>I get this error: undefined method `name' for #</p> <p>Parameters being passed on the request are below</p> <pre><code>{"utf8"=&gt;"✓", "_method"=&gt;"put", "authenticity_token"=&gt;"cxANtlyj+W+ykSnivfQTfTznkpt7yXe75E8jWI1IC+o=", "user"=&gt;{"avatar"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x000001032ac7c8 @original_filename="pictester.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"pictester.png\"\r\nContent-Type: image/png\r\n", @tempfile=#&lt;File:/var/folders/x9/gvnnn6s9585gkxw40c51d3540000gn/T/RackMultipart20130622- 10366-a8ome3&gt;&gt;}, "commit"=&gt;"upload", "id"=&gt;"1"} </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.
    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