File Uploading using Paper clip Rails Plugin


This is one of the most useful plug (Rails Plugin) in that can be used in your application when you require to upload a file as attachment to your application, its quite easy to use and with the help of paperclip scaffolding you can achieve file upload feature very easily, below i have explained the steps to create a simple application using scaffolding that enables the file upload feature with the help of paperclip plugin.

Steps:
Install the required gems to run the paperclip plugin from the below mentioned command,

$ gem sources -a http://gemcutter.org
http://gemcutter.org added to sources
$ sudo gem install view_mapper
Successfully installed view_mapper-0.2.0
1 gem installed Installing ri documentation for view_mapper-0.2.0...
Installing RDoc documentation for view_mapper-0.2.0...

1. First you need to create a rails app and change the database.yml setting and set things to install the plug in $rails student -d mysql

2 Then you have to just install the paperclip plugin into your application from the below mentioned command,

$ ./script/plugin install git://github.com/thoughtbot/paperclip.git

3. Once the plugin is installed, let me show you to create a simple scaffold with paperclip file attachment feature in it.
Just create a simple scaffold and check it out,

$ ./script/generate scaffold_for_view Student name:string branch:string comment:string --view paperclip:photo

Then you need to enter $ rake db:create and $ rake db:migrate
This will create the paperclip file attachment feature, just run $ script/server and check it out. The display looks just like the image i have mentioned at the beginning.

Source: RailsCarma

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s