Sha256: c95334c152477d48372523ce20184ddbf0053367fa9b0a2b6b103ebcd0caed36

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

module Bently
  class Carrierwave < RailsRecipe

    title 'carrierwave'
    category 'gem'
    description 'downloads and installs carrierwave gem'
    homepage 'https://github.com/jnicklas/carrierwave/blob/master/README.md'

    def initialize
      gem 'carrierwave'
      bundle
      todo 'Start off by generating an uploader:'
      say '  rails generate uploader Avatar', ''
      todo 'For use with ActiveRecord:'
      say 'Make sure you are loading CarrierWave after loading your ORM, otherwise you\'ll need to require the relevant extension manually, e.g.:', '-'
      say '  require \'carrierwave/orm/activerecord\'','1', :magenta
      say 'Add a string column to the model you want to mount the uploader on:','-'
      say '  add_column :users, :avatar, :string','1', :magenta
      say 'Open your model file and mount the uploader:','-'
      say '  class User < ActiveRecord::Base','1', :magenta
      say '    mount_uploader :avatar, AvatarUploader','2', :magenta
      say '  end','3', :magenta
      say 'Now you can cache files by assigning them to the attribute, they will automatically be stored when the record is saved.','-'
      say '  u = User.new', '1', :magenta
      say '  u.avatar = params[:file]', '2', :magenta
      say '  u.avatar = File.open(\'somewhere\')', '3', :magenta
      say '  u.save!', '4', :magenta
      say '  u.avatar.url # => \'/url/to/file.png\'', '5', :magenta
      say '  u.avatar.current_path # => \'path/to/file.png\'', '6', :magenta
      say '  u.avatar.identifier # => \'file.png\'', '7', :magenta
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bently-1.0.2 lib/bently/recipe/carrierwave.rb
bently-1.0.1 lib/bently/recipe/carrierwave.rb