Guest User

Untitled

a guest
Apr 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. class TopicsController < ApplicationController
  2. before_filter :find_forum
  3. before_filter :find_topic, :only => [:show, :edit, :update, :destroy]
  4. def index
  5. respond_to do |format|
  6. format.html { redirect_to forum_path(@forum) }
  7. format.xml do
  8. @topics = find_forum.topics.paginate(:page => current_page)
  9. render :xml => @topics
  10. end
  11. end
  12. end
  13. def edit
  14. end
  15. def show
  16. respond_to do |format|
  17. format.html do
  18. if logged_in?
  19. current_user.seen!
  20. (session[:topics] ||= {})[@topic.id] = Time.now.utc
  21. end
  22. @topic.hit! unless logged_in? && @topic.user_id == current_user.id
  23. @posts = @topic.posts.paginate :page => current_page
  24. @post = Post.new
  25. end
  26. format.xml { render :xml => @topic }
  27. end
  28. end
  29. def new
  30. @topic = Topic.new
  31. @topic.forum = @forum
  32. respond_to do |format|
  33. format.html # new.html.erb
  34. format.xml { render :xml => @topic }
  35. end
  36. end
  37. def create
  38. @topic = current_user.post @forum, params[:topic]
  39. respond_to do |format|
  40. if @topic.new_record?
  41. format.html { render :action => "new" }
  42. format.xml { render :xml => @topic.errors, :status => :unprocessable_entity }
  43. else
  44. flash[:notice] = 'topic created'
  45. format.html { redirect_to(forum_topic_path(@forum, @topic)) }
  46. format.xml { render :xml => @topic, :status => :created, :location => forum_topic_url(@forum, @topic) }
  47. end
  48. end
  49. end
  50. def update
  51. current_user.revise @topic, params[:topic]
  52. respond_to do |format|
  53. if @topic.errors.empty?
  54. flash[:notice] = 'topic updated'
  55. format.html { redirect_to(forum_topic_path(@forum, @topic)) }
  56. format.xml { head :ok }
  57. else
  58. format.html { render :action => "edit" }
  59. format.xml { render :xml => @topic.errors, :status => :unprocessable_entity }
  60. end
  61. end
  62. end
  63. def destroy
  64. @topic.destroy
  65. respond_to do |format|
  66. format.html { redirect_to(@forum) }
  67. format.xml { head :ok }
  68. end
  69. end
  70. protected
  71. def find_forum
  72. @forum = Forum.find_by_permalink(params[:forum_id])
  73. end
  74. def find_topic
  75. @topic = @forum.topics.find_by_permalink(params[:id])
  76. end
  77. end
Add Comment
Please, Sign In to add comment