Upload files with Paperclip System-file-manager plugins - suggested by Soleone, 3 months ago

Introducing the Paperclip plugin

There is a very cool and easy to use plugin out there for uploading and showing files in your Rails app, it’s called Paperclip.

You can use it for images or music or whatever file-types you like. When you use it for images, you need to have ImageMagick installed somewhere in your Path. (Note: You don’t need RMagick though!)

Unfortunately the plugin is not available from a normal plugin repository as far as i know. This is why you have to download it using Git or SVN – I’m gonna use Git in this example:

1. Installation – Get the plugin from the Git repository:

cd vendor/plugins

git clone git://github.com/thoughtbot/paperclip.git

2. Model – Add the has_attached_file declaration for your attribute:

3. Database – Add these 3 fields to your users table: 4. View (create) – Add this to your create- and edit-view:

Note: Be sure to set multipart = true, so that the HTML form is capable of sending files to your controller.

5. Controller – The user is created normally using:

6. View (show) – Finally we can show the files in the HTML page like this:

We can also show get the different styles we defined (relying on ImageMagick):

That’s it!

I recommend the links for Paperclip to get a better overview, but this short section should cover the basic use case.

Note: The plugin does not seem to work under Windows at the moment (at least for me), see the comments here for more information.

Applications-internet Go here for additional information: http://www.thoughtbot.com/projects/paperclip


0 Comments

Title (optional)

Text (Textile is active)


Back to all Tips