Class: Back::MediasController
- Inherits:
-
BackController
- Object
- BackController
- Back::MediasController
- Defined in:
- app/controllers/lato_media/back/medias_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #refresh_index ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 29 def create @media = LatoMedia::Media.new(attachment: params[:file]) unless @media.save render json: { error: @media.errors..to_sentence }, status: 400 return end render json: {}, status: 200 rescue => e puts e render json: {error: 'There was an internal error'}, status: 500 end |
#destroy ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 63 def destroy @media = LatoMedia::Media.find_by(id: params[:id]) return unless check_media_presence unless @media.destroy flash[:danger] = @media.errors..to_sentence redirect_to lato_media.medias_path return end flash[:success] = LANGUAGES[:lato_media][:flashes][:media_destroy_success] redirect_to lato_media.medias_path end |
#edit ⇒ Object
43 44 45 46 47 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 43 def edit core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:medias_edit]) @media = LatoMedia::Media.find_by(id: params[:id]) return unless check_media_presence end |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 8 def index core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:medias]) set_index_variables((params[:page] ? params[:page].to_i : 1)) end |
#new ⇒ Object
25 26 27 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 25 def new core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:medias_new]) end |
#refresh_index ⇒ Object
13 14 15 16 17 18 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 13 def refresh_index set_index_variables(1) respond_to do |r| r.js end end |
#show ⇒ Object
20 21 22 23 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 20 def show # use edit as default media show page redirect_to lato_media.edit_media_path(params[:id]) end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/lato_media/back/medias_controller.rb', line 49 def update @media = LatoMedia::Media.find_by(id: params[:id]) return unless check_media_presence unless @media.update(media_params) flash[:danger] = @media.errors..to_sentence redirect_to lato_media.medias_path return end flash[:success] = LANGUAGES[:lato_media][:flashes][:media_update_success] redirect_to lato_media.medias_path end |