A paper clip will not save an image in a Rails application

I am trying to use Paperclip with my Rails application to add an avatar to a user, but it will not save my image or update the database column when creating the user.

It looks like this:

class User < ActiveRecord::Base has_attached_file :avatar 

And registration form in haml:

 - form_for :user, @user, :url => { :action => "signup" }, :html => { :multipart => true } do |f| ... ... %li %div{:class => "header"} Profilepicture %div{:class => "input"} = f.file_field :avatar 

And when I look in the log, this is what the "signup" passes to:

 Parameters: {"commit"=>"Save", "action"=>"signup", "controller"=>"user/register", "user"=>{"name"=>"Micke Lisinge", "birthmonth"=>"07", "password_confirmation"=>"[FILTERED]", "nickname"=>"lisinge", "avatar"=>#<File:/tmp/RackMultipart20100426-3076-1x04oxy-0>, "gen"=>"m", "birthday"=>"23", "password"=>"[FILTERED]", "birthyear"=>"1992", "email"=>" lisinge@gmail.coma "}} [paperclip] Saving attachments. 

Paperclip says that it saves the template, but when I look in the public folder in my application, it created a system , but the system folder is empty.

So it looks like this is not saving the image in a folder.

It is processed by the form and saved in my /tmp folder.

Perhaps you guys have any clues or know what this problem might be?

+4
source share
5 answers

I got it for work.

I had to add :avatar to attr_accessible in my model .

Spending this here and hoping he will someday help someone :)

Thanks guys for your help.

+3
source

Remember to set: multipart => true in the form declaration. It bit me once or twice.

+2
source
 has_attached_file :asset, :url => "/assets/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/:id/:style/:basename.:extension" 

FYI. This code actually saved my files in the root directory of my machine "/", because the: rails_root parameter did not work. This is on Rails 3.0.0.rc

+1
source

First check if path correct for the created application. You can use avatar.path to determine this. if it doesn't return the correct path, maybe someone overrides the default paperclip path?

Also check if public / system access is available to the user on which you run the application server.

0
source

Try setting the option: path

 has_attached_file :avatar, :path => ':rails_root/public/system/:id.:extension' 
0
source

Source: https://habr.com/ru/post/1308055/


All Articles