Class: Notee::ImagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Notee::ImagesController
- Defined in:
- app/controllers/notee/images_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/notee/images_controller.rb', line 12 def create @image = Image.new @image.file = params[:image] respond_to do |format| if @image.save format.json { render json: @image, status: 200 } else format.json { render json: @image.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/notee/images_controller.rb', line 26 def destroy return unless @del_img = Image.find_by(content: params[:name]) Image.transaction do image_dir = Rails.root.to_s + "/public/notee/" File.delete(image_dir + @del_img.content) respond_to do |format| if @del_img.destroy format.json { render json: @del_img, status: 200 } else format.json { render json: @del_img.errors, status: :internal_server_error } end end end end |
#index ⇒ Object
7 8 9 10 |
# File 'app/controllers/notee/images_controller.rb', line 7 def index @images = Image.all render json: { status: 'success', images: @images} end |