app/controllers/guts/media_controller.rb in guts-1.0.8 vs app/controllers/guts/media_controller.rb in guts-1.1.0

- old
+ new

@@ -1,6 +1,6 @@ -require_dependency "guts/application_controller" +require_dependency 'guts/application_controller' module Guts # Media controller class MediaController < ApplicationController before_action :set_object @@ -9,14 +9,14 @@ # Displays a list of media # @note Depending on the object passed (polymorphic) def index @media = if @object - @object.media.paginate(page: params[:page], per_page: @per_page) - else - Medium.paginate(page: params[:page], per_page: @per_page) - end + @object.media.paginate(page: params[:page], per_page: @per_page) + else + Medium.paginate(page: params[:page], per_page: @per_page) + end end # Shows details about a single medium def show end @@ -34,40 +34,45 @@ # @note Redirects to #index if successfull or re-renders #new if not def create @medium = Medium.new medium_params if @medium.save - redirect_to polymorphic_path([@object, :media]), notice: "Media was successfully created." + flash[:notice] = 'Media was successfully created.' + redirect_to polymorphic_path([@object, :media]) else render :new end end # Updates a medium through patch # @note Redirects to #index if successfull or re-renders #edit if not def update if @medium.update(medium_params) - redirect_to polymorphic_path([@object, :media]), notice: "Media was successfully updated." + flash[:notice] = 'Media was successfully updated.' + redirect_to polymorphic_path([@object, :media]) else render :edit end end # Destroys a medium # @note Redirects to #index on success def destroy @medium.destroy - redirect_to polymorphic_path([@object, :media]), notice: "Media was successfully destroyed." + + flash[:notice] = 'Media was successfully destroyed.' + redirect_to polymorphic_path([@object, :media]) end # Handles showing the insert medium # allowing TinyMce to use it def editor_insert render :editor_insert, layout: false end private + # Sets a medium from the database using `id` param # @note This is a `before_action` callback # @private def set_medium @medium = Medium.find params[:id] @@ -87,10 +92,19 @@ end # Permits medium params from forms # @private def medium_params - params.require(:medium).permit(:title, :tags, :position, :caption, :file, :filable_type, :filable_id) + params.require(:medium).permit( + :title, + :tags, + :position, + :caption, + :file, + :filable_type, + :filable_id, + :site_id + ) end # Gets the per-page value to use # @note Default is 30 # @private