about summary refs log tree commit diff stats
path: root/app/controllers
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-20 21:27:06 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-20 21:27:06 -0400
commit2a7a19c93ee0e0d77e4e388d43f36a721c7ab715 (patch)
treec5e775bca4600d111d01d1bd7998d3b6252462e6 /app/controllers
parent74b1612e49ebd9cb29efb85f3afeb07f0e8d608a (diff)
downloadthoughts-2a7a19c93ee0e0d77e4e388d43f36a721c7ab715.tar.gz
thoughts-2a7a19c93ee0e0d77e4e388d43f36a721c7ab715.tar.bz2
thoughts-2a7a19c93ee0e0d77e4e388d43f36a721c7ab715.zip
Added post voting
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/blogs_controller.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 0d218ae..2f9df49 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb
@@ -38,4 +38,52 @@ class BlogsController < ApplicationController
38 }) 38 })
39 end 39 end
40 40
41 def upvote
42 @blog = Blog.find_by_slug(params[:slug])
43
44 raise ActiveRecord::RecordNotFound unless @blog
45 raise ActiveRecord::RecordNotFound unless @blog.published
46
47 respond_to do |format|
48 if @blog.upvote! request.remote_ip
49 format.html do
50 flash[:notice] = "You have upvoted the blog post \"#{@blog.title}\"."
51 redirect_to @blog
52 end
53 format.js { render "voted" }
54 format.xml { head :ok }
55 else
56 format.html do
57 flash[:notice] = "You have already voted on the blog post \"#{@blog.title}\"."
58 redirect_to @blog
59 end
60 format.xml { render :xml => { :error => "Someone from your IP address has already voted on this blog post."} }
61 end
62 end
63 end
64
65 def downvote
66 @blog = Blog.find_by_slug(params[:slug])
67
68 raise ActiveRecord::RecordNotFound unless @blog
69 raise ActiveRecord::RecordNotFound unless @blog.published
70
71 respond_to do |format|
72 if @blog.downvote! request.remote_ip
73 format.html do
74 flash[:notice] = "You have downvoted the blog post \"#{@blog.title}\"."
75 redirect_to @blog
76 end
77 format.js { render "voted" }
78 format.xml { head :ok }
79 else
80 format.html do
81 flash[:notice] = "You have already voted on the blog post \"#{@blog.title}\"."
82 redirect_to @blog
83 end
84 format.xml { render :xml => { :error => "Someone from your IP address has already voted on this blog post."} }
85 end
86 end
87 end
88
41end 89end