Topic: Paperclip not saving any images
Hey everyone,
I was hoping this would've been a 5 minute task, but again, my database is not getting the values, this time from paperclip.
I tried this on a test app on my Mac, and it works fine. Go figure!
The only difference is on My Mac I'm just using Mongrel, and SQLite for my DB. The main app I have on Ubuntu LTS 8.04 LTS, running on Apache2, mod_rails 2.2.5, with MySQL 5 for my DB.
I got Paperclip installed, generated the paperclip, and called it avatar, of which it associates to the User model.
In the User model I added:
has_attached_file :avatar, :url => "/avatars/users/:id/:basename.:extension", :path => ":rails_root/public/avatars/users/:id/:basename.:extension"
# Added the following lines to attr_accessible
attr_accessible [everything else], :avatar_file_name, :avatar_content_type, :avatar_file_size, :avatar_updated_atThen in my form for new/update user, I have:
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= image_tag @user.avatar.url, :width => "150px", :height => "150px" %>
<table>
<tr>
<td>First Name</td>
<td><%= f.text_field :first %></td>
</tr>
<tr>
<td>Last Name</td>
<td><%= f.text_field :last %></td>
</tr>
<tr>
<td>Login</td>
<td><%= f.text_field :login %></td>
</tr>
<tr>
<td>E-mail Address</td>
<td><%= f.text_field :email %></td>
</tr>
<tr>
<td>Upload an avatar</td>
<td><%= f.file_field :avatar %>
</tr>
<tr>
<td>Password</td>
<td><%= f.password_field :password %></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><%= f.password_field :password_confirmation %></td>
</tr>
<% if admin? %>
<tr>
<td>Administrator Role</td>
<td><%= f.text_field :admin %></td>
</tr>
<% else %>
<% end %>
</table>
<p><%= f.submit 'Update Account' %></p>Save everything, update the current user in this case, and no go. I look in my Users table in my DB, with a good ol' "select * from users where id = 1;", and all those fields are NULL as I expected.
Ok, so now I go look in log/development.log. I see:
Processing UsersController#update (for 70.89.247.75 at 2009-11-16 17:32:15) [PUT]
Parameters: {"user"=>{"password_confirmation"=>"", "admin"=>"1", "last"=>"Brinkerhoff", "first"=>"Justin", "avatar"=>#<File:/tmp/RackMultipart.18774.1>, "password"=>"", "login"=>"justin", "email"=>"justinbrinkerhoff@gmail.com"}, "commit"=>"Update Account", "authenticity_token"=>"9z5P+7wcmujDCYkcl0M5OjuCPQPnpUF+1mYp2aBVIew=", "id"=>"1"}
User Columns (77.4ms) SHOW FIELDS FROM `users`
User Load (84.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 1)
WARNING: Can't mass-assign these protected attributes: avatar
SQL (75.5ms) BEGIN
User Exists (77.5ms) SELECT `users`.id FROM `users` WHERE (LOWER(`users`.`login`) = BINARY 'justin' AND `users`.id <> 1) LIMIT 1
User Exists (82.1ms) SELECT `users`.id FROM `users` WHERE (LOWER(`users`.`email`) = BINARY 'justinbrinkerhoff@gmail.com' AND `users`.id <> 1) LIMIT 1
[paperclip] Saving attachments.
SQL (87.5ms) COMMIT
Redirected to http://iloveorganic.co.uk:3000/users/1/edit
Completed in 628ms (DB: 638) | 302 Found [http://iloveorganic.co.uk/users/1]
SQL (79.6ms) SET NAMES 'utf8'
SQL (76.3ms) SET SQL_AUTO_IS_NULL=0So it appears that Paperclip is not processing the uploads properly, or something. I've tried searching around for a solution, but couldn't quite find anything helpful for this strange issue...
Has anyone came across this in the past?
If anyone has some good insight on this, I'd be much appreciative. ![]()
Last edited by jmbrink26 (2009-11-16 22:37:45)