Guest User

Untitled

a guest
Apr 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class TopicsController < ApplicationController
  2.  
  3. before_filter :set_topic, :only => [:show, :edit, :update, :destroy]
  4.  
  5. def index
  6. @topics = current_user.topics
  7. end
  8.  
  9. def show
  10. @topic.update_topic_hits
  11. @topic_hits = @topic.topic_hits.paginate(:page => params[:page] || 1, :per_page => params[:per_page])
  12. end
  13.  
  14. def new
  15. @topic = Topic.new
  16. end
  17.  
  18. def edit
  19. end
  20.  
  21. def create
  22. @topic = Topic.new(params[:topic])
  23. @topic.user = current_user
  24.  
  25. if @topic.save
  26. flash[:notice] = 'News Monitor was successfully created.'
  27. redirect_to @topic
  28. else
  29. render :action => "new"
  30. end
  31. end
  32.  
  33. def update
  34. if @topic.update_attributes(params[:topic])
  35. flash[:notice] = 'News Monitor was successfully updated.'
  36. redirect_to @topic
  37. else
  38. render :action => "edit"
  39. end
  40. end
  41.  
  42. def destroy
  43. @topic = Topic.find(params[:id])
  44. @topic.destroy
  45. redirect_to(topics_url)
  46. end
  47.  
  48. protected
  49. def set_topic
  50. @topic = Topic.find(params[:id])
  51. access_denied unless @topic.user == current_user
  52. end
  53. end
Add Comment
Please, Sign In to add comment