about summary refs log tree commit diff stats
path: root/app/controllers/blogs_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/blogs_controller.rb')
-rw-r--r--app/controllers/blogs_controller.rb83
1 files changed, 83 insertions, 0 deletions
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 8ee472e..6e80754 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb
@@ -1,10 +1,93 @@
1
2
1class BlogsController < ApplicationController 3class BlogsController < ApplicationController
4 include ApplicationHelper
5
6 def summary
7 @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10)
8 if not params[:page]
9 @main_page = true
10 end
11 end
12
13 def index
14 @blogs = Blog.where(published: true).order(published_at: :desc)
15
16 respond_to do |format|
17 format.html
18 format.atom
19 end
20 end
2 21
3 def show 22 def show
4 @blog = Blog.find_by_slug(params[:slug]) 23 @blog = Blog.find_by_slug(params[:slug])
5 24
6 raise ActiveRecord::RecordNotFound unless @blog 25 raise ActiveRecord::RecordNotFound unless @blog
7 raise ActiveRecord::RecordNotFound unless @blog.published 26 raise ActiveRecord::RecordNotFound unless @blog.published
27
28 @prev = @blog.prev
29 @next = @blog.next
30
31 body = stripped_markdown(@blog.body)
32
33 set_meta_tags(og: {
34 title: @blog.title,
35 type: "article",
36 description: body[0, 299],
37 url: blog_url(@blog, host: "www.fourisland.com"),
38 article: {
39 published_time: @blog.published_at.iso8601,
40 modified_time: @blog.updated_at.iso8601
41 }
42 })
43 end
44
45 def upvote
46 @blog = Blog.find_by_slug(params[:slug])
47
48 raise ActiveRecord::RecordNotFound unless @blog
49 raise ActiveRecord::RecordNotFound unless @blog.published
50
51 respond_to do |format|
52 if @blog.upvote! request.remote_ip
53 format.html do
54 flash[:notice] = "You have upvoted the blog post \"#{@blog.title}\"."
55 redirect_to @blog
56 end
57 format.js { render "voted" }
58 format.xml { head :ok }
59 else
60 format.html do
61 flash[:notice] = "You have already voted on the blog post \"#{@blog.title}\"."
62 redirect_to @blog
63 end
64 format.xml { render :xml => { :error => "Someone from your IP address has already voted on this blog post."} }
65 end
66 end
67 end
68
69 def downvote
70 @blog = Blog.find_by_slug(params[:slug])
71
72 raise ActiveRecord::RecordNotFound unless @blog
73 raise ActiveRecord::RecordNotFound unless @blog.published
74
75 respond_to do |format|
76 if @blog.downvote! request.remote_ip
77 format.html do
78 flash[:notice] = "You have downvoted the blog post \"#{@blog.title}\"."
79 redirect_to @blog
80 end
81 format.js { render "voted" }
82 format.xml { head :ok }
83 else
84 format.html do
85 flash[:notice] = "You have already voted on the blog post \"#{@blog.title}\"."
86 redirect_to @blog
87 end
88 format.xml { render :xml => { :error => "Someone from your IP address has already voted on this blog post."} }
89 end
90 end
8 end 91 end
9 92
10end 93end