Class: Guts::ContentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Guts::ContentsController
- Defined in:
- app/controllers/guts/contents_controller.rb
Overview
Contents controller
Instance Method Summary collapse
-
#create ⇒ Object
Creates a content through post.
-
#destroy ⇒ Object
Destroys a content.
-
#edit ⇒ Object
Editting of a content.
-
#index ⇒ Object
Displays a list of contents.
-
#new ⇒ Object
Creation of a content.
-
#show ⇒ Object
Shows details about a single content.
-
#update ⇒ Object
Updates a content through patch.
Instance Method Details
#create ⇒ Object
Note:
Redirects to #index if successfull or re-renders #new if not
Creates a content through post
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/guts/contents_controller.rb', line 36 def create @content = Content.new content_params @content.user = current_user @content.type = @type @content if @content.save flash[:notice] = "#{@content.type.title} was successfully created." redirect_to edit_content_path(@content) else render :new end end |
#destroy ⇒ Object
Note:
Redirects to #index on success
Destroys a content
66 67 68 69 70 71 72 |
# File 'app/controllers/guts/contents_controller.rb', line 66 def destroy @content @content.destroy flash[:notice] = "#{@content.type.title} was successfully destroyed." redirect_to contents_path(type: @content.type.slug) end |
#edit ⇒ Object
Editting of a content
30 31 32 |
# File 'app/controllers/guts/contents_controller.rb', line 30 def edit @content end |
#index ⇒ Object
Note:
This method must have a type set
Displays a list of contents
12 13 14 15 16 |
# File 'app/controllers/guts/contents_controller.rb', line 12 def index @contents = policy_scope(Content) .where(type: @type) .paginate(page: params[:page], per_page: @per_page) end |
#new ⇒ Object
Creation of a content
19 20 21 22 |
# File 'app/controllers/guts/contents_controller.rb', line 19 def new @content = Content.new @content end |
#show ⇒ Object
Shows details about a single content
25 26 27 |
# File 'app/controllers/guts/contents_controller.rb', line 25 def show @content end |
#update ⇒ Object
Note:
Redirects to #index if successfull or re-renders #edit if not
Updates a content through patch
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/guts/contents_controller.rb', line 53 def update @content if @content.update(content_params) flash[:notice] = "#{@content.type.title} was successfully updated." redirect_to edit_content_path(@content) else render :edit end end |