diff options
Diffstat (limited to 'app/controllers/blogs_controller.rb')
-rw-r--r-- | app/controllers/blogs_controller.rb | 48 |
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 | |||
41 | end | 89 | end |