Skip to content

Commit

Permalink
add in a recipe for paperclip
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdempsey committed Sep 8, 2010
1 parent 7ec1a90 commit a2fab31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ and want to verify things worked correctly
* use aruba to test beet - http://github.com/aslakhellesoy/aruba

* write recipes for
* paperclip
* multiple file uploads
* facebook connect with devise - http://stackoverflow.com/questions/3580557/rails-3-using-devise-how-to-allow-someone-to-log-in-using-their-facebook-account
29 changes: 29 additions & 0 deletions lib/beet/recipes/rails3/file_uploads/paperclip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
gem 'paperclip'

model_name = ask "Name of the model to add an attachment to, e.g. user_profile"
attachment_name = ask "Name for the attached file, e.g. has_attached_file :avatar"
underscored_model_name = model_name.underscore

in_root do
if File.exists?("app/models/#{model_name}.rb")
table_name = underscored_model_name.pluralize

generate "migration add_#{attachment_name}_to_#{table_name}"
migration_file = Dir["db/migrate/*add_#{attachment_name}_to_#{table_name}*"].first
add_after "db/migrate/#{migration_file}.rb", 'def self.up', do
%{
add_column :#{table_name}, #{attachment_name}_file_name:string
add_column :#{table_name}, #{attachment_name}_content_type:string
add_column :#{table_name}, #{attachment_name}_file_size:integer
add_column :#{table_name}, #{attachment_name}_updated_at:datetime
}
end
else
generate "model #{model_name} #{attachment_name}_file_name:string #{attachment_name}_content_type:string #{attachment_name}_file_size:integer #{attachment_name}_updated_at:datetime"
end

add_after "app/models/#{underscored_model_name}.rb", "class #{model_name.camelize} < ActiveRecord::Base", "has_attached_file :#{attachment_name}, :styles => { :thumb => '50x' }"

end

rake "db:migrate"

0 comments on commit a2fab31

Please sign in to comment.