app/controllers/guts/contents_controller.rb in guts-1.0.8 vs app/controllers/guts/contents_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
# Contents controller
class ContentsController < ApplicationController
before_action :set_content, only: [:show, :edit, :update, :destroy]
@@ -32,34 +32,39 @@
@content = Content.new content_params
@content.user = current_user
@content.type = @type
if @content.save
- redirect_to contents_path(type: @content.type.slug), notice: "#{@content.type.title} was successfully created."
+ flash[:notice] = "#{@content.type.title} was successfully created."
+ redirect_to contents_path(type: @content.type.slug)
else
render :new
end
end
# Updates a content through patch
# @note Redirects to #index if successfull or re-renders #edit if not
def update
if @content.update(content_params)
- redirect_to contents_path(type: @content.type.slug), notice: "#{@content.type.title} was successfully updated."
+ flash[:notice] = "#{@content.type.title} was successfully updated."
+ redirect_to contents_path(type: @content.type.slug)
else
render :edit
end
end
- # Destroys a category
+ # Destroys a content
# @note Redirects to #index on success
def destroy
@content.destroy
- redirect_to contents_path(type: @content.type.slug), notice: "#{@content.type.title} was successfully destroyed."
+
+ flash[:notice] = "#{@content.type.title} was successfully destroyed."
+ redirect_to contents_path(type: @content.type.slug)
end
private
+
# Sets a content from the database using `id` param
# @note This is a `before_action` callback
# @private
def set_content
@content = Content.find params[:id]
@@ -67,20 +72,28 @@
# Sets the type from either params or current content object
# @note This is a `before_action` callback
# @private
def set_type
- @type = if @content and !@content.new_record?
- @content.type
- else
- Type.find params[:type]
- end
+ @type = if @content && !@content.new_record?
+ @content.type
+ else
+ Type.find params[:type]
+ end
end
- # Permits category params from forms
+ # Permits content params from forms
# @private
def content_params
- params.require(:content).permit(:title, :slug, :content, :visible, :tags, category_ids: [])
+ params.require(:content).permit(
+ :title,
+ :slug,
+ :content,
+ :visible,
+ :tags,
+ :site_id,
+ category_ids: []
+ )
end
# Gets the per-page value to use
# @note Default is 30
# @private