Skip to content

Instantly share code, notes, and snippets.

@djs070
Created March 1, 2013 02:50
Show Gist options
  • Save djs070/5062134 to your computer and use it in GitHub Desktop.
Save djs070/5062134 to your computer and use it in GitHub Desktop.
Add a file attachment to a rails model using paperclip

Add an attachment field to a rails model using paperclip

Install the gem

In Gemfile

gem "paperclip", "~> 3.0"

Run bundler

> bundle install

Generate the paperclip

> rails g paperclip ModelName AttachmentName

> rake db:migrate

In ModelName.rb

attr_accessible :attachment_name
has_attached_file :attachment_name

In _form.html.erb

<div class="field">
  <%= f.label :attachment_name %><br />
  <%= f.file_field :attachment_name %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment