Paperclip learning to use notes

tags: Rails  Blog  HTML

 

   paperclip Is a plugin for rails processing attachments, compared to the pastattachment_fuWaiting for better efficiency and use.

 

  paperclipUploaded image attachments do not require ImageMagick to be installed if you do not need to change the size. Paperclip for image processing under the window platform is easy to get such error message

。。。is not recognized by the 'identify' command

It took 1.5h to finally find a solution like this on a walled blog: Create a new paperclip.rb file in the project's config/iniinitializers directory and write the following code:

Paperclip.options[:command_path] = 'D://Program Files//ImageMagick' # Your imageMagick installation directory
Paperclip.options[:swallow_stderr] = false

 

Modify the User model Add the following code

has_attached_file :avatar, :styles => { :medium => "200x200>", :thumb => "32x32>" }

Execute the following code to add 4 columns to the users table

script/generate paperclip User avatar 

 

Form:

<% form_for current_users, :html => {:multipart => true} do|form|%>       
γ€€<%= form.file_field :avatar %>
   <%=form.submit 'Upload ' %>
<% end %> 

 

Because the User model is generated using the restful_authentication plugin, if it is uploaded, it will not work, and the uploaded attachment will be filtered out. After uploading, the column related to the attachment in the Users table is still nill, then look at the console information:

WARNING: Can't mass-assign these protected attributes: avatar

I searched the Internet and I understand that it is the reason. The restful_authentication helped us generate some of these in the User model.

# anything else you want your user to change should be added here.
  attr_accessible :login, :email, :password, :password_confirmation

Adding on the attr_accessible: avater is ok.

 

As for other ways of using paperclip, continue to study later. Today only records problems encountered during the use process.

 

 

 

 

 

 

 

 

 

 

 

Intelligent Recommendation

Rails3 paperclip Add a watermark

[url]https://gist.github.com/784445[/url] Gemfile added New file /lib/paperclip_processors/watermark.rb app/models/image.rb app/views/images/_form.html.erb app/views/show.html.erb...

ruby --Paperclip::NotIdentifiedByImageMagickError

First of all, if you encounter this problem, Paperclip :: NotIdentifiedByImageMagickError, under the first check whether the environment variable configuration of the path ImagicMagick. Under cmd path...

rails3 + paperclip picture watermarked

1. New Project, and remove index.html 2. Modify Gemfile add paperclip 3. New asset r 4. Add paperclip support 5. New lib / paperclip_processors / watermark.rb, source file: [url=http://gist.github.com...

Rails Paperclip and ImageMagick

on the Internet for about plug on paperclip, and found what they say, but did not set the size of the effect, but later found the need to install an image editing software for the job: ImageMagick [B]...

More Recommendation

Learn your paperclip

Why can't 80% of the code farmers can't do architects? >>>   First, see PaperClip.rb to see it from a very important way, that ishas_attached_file(name, options = {}) La! Next, it c...

PaperClip Tips Command Is Not Recognized by THE

2019 Unicorn Enterprise Heavy Glour Recruitment Python Engineer Standard >>> Use PaperClip to cut pictures, prompts the following error: Solution, build a custom_requires.rb file in the confi...

Kettle4.1 learning to use notes

Recently, the company used an ETL tool. Google took a look and found that Kettle used more people, so I downloaded it and tried it! First of all, I downloaded some tutorials from the Internet, mainly ...

Makefile use (learning notes)

Makefile rules composition target prerequisites command target One or more of the object files depend on the files in the prerequisites, and the generation rules are defined in the command. To put it ...

Maven learning, use notes

Why do 80% of the code farmers can't be architects? >>>   Maven usage notes I have been using Maven for a while, and I have used it as a build tool for several projects. It feels ve...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top