Class: CostumesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CostumesController
- Defined in:
- app/controllers/costumes_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/costumes_controller.rb', line 22 def create max_position = current_user.costumes.order(position: :desc).first.try(:position) || -1 attrs = { basename: costume_params[:file].original_filename, preset: false, position: max_position + 1, } costume = current_user.costumes.create!(attrs) path = costume.path FileUtils.mkdir_p(path.dirname) File.open(path, "wb") do |f| f.write(costume_params[:file].read) end index render action: "index" end |
#destroy ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/costumes_controller.rb', line 43 def destroy costume = current_user.costumes.where(id: params[:id]).first FileUtils.rm_f(costume.path) costume.destroy index render action: "index" end |
#index ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/controllers/costumes_controller.rb', line 6 def index if signed_in? @costumes = current_user.costumes.with_preset else @costumes = Costume.presets end @costumes = @costumes.merge(Costume.default_order) end |
#show ⇒ Object
15 16 17 18 19 20 |
# File 'app/controllers/costumes_controller.rb', line 15 def show name = params[:basename].sub(/\.png$/, "") costume = current_user.costumes.where(name: name).first send_file costume.path, type: "image/png", disposition: "inline", x_send_file: true end |