Guest User

Untitled

a guest
Apr 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. class ForumsController < ApplicationController
  2.  
  3. before_filter(:only => [ :new, :edit, :destroy, :update, :create ]) { |c| c.role_required 'editor' }
  4.  
  5. # GET /forums
  6. # GET /forums.xml
  7. def index
  8. @forums = Forum.find(:all)
  9.  
  10. respond_to do |format|
  11. format.html # index.html.erb
  12. format.xml { render :xml => @forums }
  13. end
  14. end
  15.  
  16. # GET /forums/1
  17. # GET /forums/1.xml
  18. def show
  19. @forum = Forum.find(params[:id])
  20.  
  21. respond_to do |format|
  22. format.html # show.html.erb
  23. format.xml { render :xml => @forum }
  24. end
  25. end
  26.  
  27. # GET /forums/new
  28. # GET /forums/new.xml
  29. def new
  30. @forum = Forum.new
  31.  
  32. respond_to do |format|
  33. format.html # new.html.erb
  34. format.xml { render :xml => @forum }
  35. end
  36. end
  37.  
  38. # GET /forums/1/edit
  39. def edit
  40. @forum = Forum.find(params[:id])
  41. end
  42.  
  43. # POST /forums
  44. # POST /forums.xml
  45. def create
  46. @forum = Forum.new(params[:forum])
  47.  
  48. respond_to do |format|
  49. if @forum.save
  50. flash[:notice] = 'Forum was successfully created.'
  51. format.html { redirect_to(@forum) }
  52. format.xml { render :xml => @forum, :status => :created, :location => @forum }
  53. else
  54. format.html { render :action => "new" }
  55. format.xml { render :xml => @forum.errors, :status => :unprocessable_entity }
  56. end
  57. end
  58. end
  59.  
  60. # PUT /forums/1
  61. # PUT /forums/1.xml
  62. def update
  63. @forum = Forum.find(params[:id])
  64.  
  65. respond_to do |format|
  66. if @forum.update_attributes(params[:forum])
  67. flash[:notice] = 'Forum was successfully updated.'
  68. format.html { redirect_to(@forum) }
  69. format.xml { head :ok }
  70. else
  71. format.html { render :action => "edit" }
  72. format.xml { render :xml => @forum.errors, :status => :unprocessable_entity }
  73. end
  74. end
  75. end
  76.  
  77. # DELETE /forums/1
  78. # DELETE /forums/1.xml
  79. def destroy
  80. @forum = Forum.find(params[:id])
  81. @forum.destroy
  82.  
  83. respond_to do |format|
  84. format.html { redirect_to(forums_url) }
  85. format.xml { head :ok }
  86. end
  87. end
  88. end
Add Comment
Please, Sign In to add comment