Alpha version.
Install Paperclip plugin and paperclipped_assets plugin
cd vendors/plugins/ git clone git://github.com/thoughtbot/paperclip.git git clone git://github.com/hasclass/paperclipped_assets.gitGenerate migration for the “paperclipped_assets”-table
script/generate paperclipped_assetsRun Migration
rake db:migrateVoilà
class Client < ActiveRecord::Base has_paperclipped_asset :logo has_paperclipped_asset :another_file end class User < ActiveRecord::Base has_paperclipped_asset :avatar endviews/clients/_form.html.erb
<% form_for @client, :html => {:multipart => true} do |f| %> <%= f.file_field :logo_data %> <%= f.file_field :another_file_data %> <%= f.submit ‘save’ %> <% end %>views/clients/show.html.erb
<%= image_tag @client.logo if @client.logo %> <%= link_to_if @client.another_file, ‘download file’, @client.another_file %>views/users/_form.html.erb
<% form_for @user, :html => {:multipart => true} do |f| %> <%= f.file_field :avatar_data %> <%= f.submit ‘save’ %> <% end %>views/users/show.html.erb
<%= image_tag @user.avatar if @user.avatar %> <%= image_tag @user.avatar.url(:thumb) if @user.avatar %> <%= image_tag @user.avatar.url(:small) if @user.avatar %> <%= image_tag @user.avatar.url(:medium) if @user.avatar %>no additional code needed
The #to_s returns the public url of the file, so that we can:
<%= link_to ‘download file’, @client.logo %>Coming soon.