Class: Bently::Carrierwave
- Inherits:
-
RailsRecipe
- Object
- Recipe
- RubyRecipe
- RailsRecipe
- Bently::Carrierwave
- Defined in:
- lib/bently/recipe/carrierwave.rb
Constant Summary
Constants inherited from RubyRecipe
Instance Method Summary collapse
-
#initialize ⇒ Carrierwave
constructor
A new instance of Carrierwave.
Methods inherited from RailsRecipe
Methods inherited from RubyRecipe
Methods inherited from Recipe
#append, breakdown, category, #code, #create, description, homepage, #insert, #modify, #operate, #operations, #prepend, #remove, #requirement, #run, #say, title, #todo, #usage, version, #warn
Constructor Details
#initialize ⇒ Carrierwave
Returns a new instance of Carrierwave.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bently/recipe/carrierwave.rb', line 9 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 |