Class: Statixite::MediaController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Statixite::MediaController
- Defined in:
- app/controllers/statixite/media_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/statixite/media_controller.rb', line 23 def create @media = @site.media.new(file: params[:file]) if @media.valid? gs = GitService.new(@site.site_clone_path, @site.site_remote).make_changes do @media.save end status = 200 response = { message: "success", media: @media } else status = 400 response = { error: @media.errors..join(',') } end respond_to do |format| format.json{ render :json => response, :status => status } end end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/statixite/media_controller.rb', line 40 def destroy @media = @site.media.find(params[:id]) if @media.destroy flash[:notice] = 'Image deleted' redirect_to :action => :index else flash[:alert] = 'Something went wrong' redirect_to :action => :index end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/statixite/media_controller.rb', line 5 def index @media_index = @site.media.order(:created_at => "DESC").page(params[:page]).per(6) @media = Media.new respond_to do |format| format.js format.html format.json { render :json => @media_index } end end |
#show ⇒ Object
16 17 18 19 20 21 |
# File 'app/controllers/statixite/media_controller.rb', line 16 def show @media = Media.find(params[:id]) content_type = MIME::Types.type_for(@media.file.path).first.content_type file = params[:file_name].include?("thumb") ? @media.file.thumb.path : @media.file.path send_file file, :type => content_type, :disposition => :inline end |