Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.90 KB | None | 0 0
  1. class Admin::ForumsController < ApplicationController
  2.     layout "admin"
  3.     before_action :find_forum, only: [:edit, :update, :destroy]
  4.    
  5.     def index
  6.         @forums = Fora.all
  7.         render :template => "admin/forums/index"
  8.     end
  9.     def new
  10.         @forum = Fora.new
  11.         render :template => "admin/forums/new"
  12.     end
  13.     def create
  14.         @forum = Fora.new(forum_params)
  15.  
  16.         if @forum.save
  17.             redirect_to admin_forums_path, notice: "Forum crée avec succés."
  18.         else
  19.             render 'new'
  20.         end
  21.     end
  22.  
  23.     def edit
  24.     end
  25.  
  26.     def update
  27.         if @forum.update(forum_params)
  28.             redirect_to admin_forums_path, notice: "Forum modifié avec succés."
  29.         else
  30.             render 'edit'
  31.         end
  32.     end
  33.  
  34.     def destroy
  35.         @forum.destroy
  36.         redirect_to admin_forums_path, notice: "Forum supprimé avec succés."
  37.     end
  38.  
  39.     private
  40.     def find_forum
  41.         @forum = Fora.find(params[:id])
  42.     end
  43.     def forum_params
  44.         params.require(:forum).permit(:title, :content)
  45.     end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement