Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

hasclass/paperclipped_assets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Helper model for file/asset handling.

Alpha version.

Installation

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.git

Generate migration for the “paperclipped_assets”-table

script/generate paperclipped_assets

Run Migration

rake db:migrate

Voilà

Example

in your model

class Client < ActiveRecord::Base has_paperclipped_asset :logo has_paperclipped_asset :another_file end class User < ActiveRecord::Base has_paperclipped_asset :avatar end

in your view

views/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 %>

in your controller

no additional code needed

Hints

The #to_s returns the public url of the file, so that we can:

<%= link_to ‘download file’, @client.logo %>

How it works

Coming soon.

About

A model for file/asset handling. Referenced by polymorphic association. Uses Paperclip.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published