aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/blog_posts_controller.rb21
-rw-r--r--app/models/blog_comment.rb12
-rw-r--r--app/views/admin/blog/comments/index.html.erb12
-rw-r--r--app/views/blog_posts/show.html.erb37
4 files changed, 76 insertions, 6 deletions
diff --git a/app/controllers/blog_posts_controller.rb b/app/controllers/blog_posts_controller.rb
index 7ddb7b8..caaa336 100644
--- a/app/controllers/blog_posts_controller.rb
+++ b/app/controllers/blog_posts_controller.rb
@@ -2,6 +2,7 @@ class BlogPostsController < ApplicationController
before_filter :find_all_blog_posts, :find_all_blog_categories
before_filter :find_page
+ before_filter :find_blog_post, :only => [:show, :comment]
def index
# you can use meta fields from your model instead (e.g. browser_title)
@@ -10,15 +11,33 @@ class BlogPostsController < ApplicationController
end
def show
- @blog_post = BlogPost.live.find(params[:id])
+ @blog_comment = BlogComment.new
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @blogs in the line below:
present(@page)
end
+ def comment
+ if (@blog_comment = BlogComment.create(params[:blog_comment])).valid?
+ if BlogComment::Moderation.enabled?
+ flash[:notice] = t('.thank_you_moderated')
+ redirect_back_or_default blog_post_url(params[:id])
+ else
+ redirect_to blog_post_url(params[:id],
+ :anchor => "comment-#{@blog_comment.to_param}")
+ end
+ else
+ render :action => 'show'
+ end
+ end
+
protected
+ def find_blog_post
+ @blog_post = BlogPost.live.find(params[:id])
+ end
+
def find_all_blog_posts
unless params[:category_id].present?
@blog_posts = BlogPost.live
diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb
index 28139e7..cc890fa 100644
--- a/app/models/blog_comment.rb
+++ b/app/models/blog_comment.rb
@@ -1,8 +1,18 @@
class BlogComment < ActiveRecord::Base
+ filters_spam :author_field => :name,
+ :email_field => :email,
+ :message_field => :message
+
belongs_to :post, :class_name => 'BlogPost'
- acts_as_indexed :fields => [:name, :email, :body]
+ acts_as_indexed :fields => [:name, :email, :message]
+
+ alias_attribute :message, :body
+
+ validates_presence_of :name, :message
+ validates_format_of :email,
+ :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
named_scope :unmoderated, :conditions => {:state => nil}
named_scope :approved, :conditions => {:state => 'approved'}
diff --git a/app/views/admin/blog/comments/index.html.erb b/app/views/admin/blog/comments/index.html.erb
index c5e911b..940ba47 100644
--- a/app/views/admin/blog/comments/index.html.erb
+++ b/app/views/admin/blog/comments/index.html.erb
@@ -3,24 +3,28 @@
<% if searching? %>
<h2><%= t('shared.admin.search.results_for', :query => params[:search]) %></h2>
<% if @blog_comments.any? %>
- <%= will_paginate @blog_comments %>
+ <%=# will_paginate @blog_comments
+ %>
<ul>
<%= render :partial => "blog_comments",
:collection => @blog_comments %>
</ul>
- <%= will_paginate @blog_comments %>
+ <%=# will_paginate @blog_comments
+ %>
<% else %>
<p><%= t('admin.search_no_results') %></p>
<% end %>
<% else %>
<% if @blog_comments.any? %>
- <%= will_paginate @blog_comments %>
+ <%=# will_paginate @blog_comments
+ %>
<%= render :partial => "sortable_list" %>
- <%= will_paginate @blog_comments %>
+ <%=# will_paginate @blog_comments
+ %>
<% else %>
<h3>
<%= t('.no_items_yet',
diff --git a/app/views/blog_posts/show.html.erb b/app/views/blog_posts/show.html.erb
index 2a6fa12..cf51e0c 100644
--- a/app/views/blog_posts/show.html.erb
+++ b/app/views/blog_posts/show.html.erb
@@ -3,6 +3,8 @@
<% content_for :body_content_left do %>
<%= @blog_post.body %>
+ <hr />
+
<% if (categories = @blog_post.categories).any? %>
<div class='post_categories'>
<span class='filed_in'><%= t('.filed_in') %></span>
@@ -15,6 +17,41 @@
</ul>
</div>
<% end %>
+
+ <hr />
+ <% if (comments = @blog_post.comments.approved).any? %>
+ <h2><%= t('.comments') %></h2>
+ <% comments.each do |comment| %>
+ <div class='blog_comment_message'>
+ <p>
+ <%= comment.message.to_s.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>") %>
+ </p>
+ </div>
+ <p class='blog_comment_author'>
+ <%= t('.comment_by', :who => comment.name) %>
+ <%= ", #{time_ago_in_words(comment.created_at)}".html_safe %>
+ </p>
+ <% end %>
+ <hr />
+ <% end %>
+
+ <% form_for [:blog_post, @blog_comment] do |f| %>
+ <div class='field'>
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ </div>
+ <div class='field'>
+ <%= f.label :email %>
+ <%= f.text_field :email %>
+ </div>
+ <div class='field message_field'>
+ <%= f.label :message %>
+ <%= f.text_area :message, :rows => 6 %>
+ </div>
+ <div class='field form-actions'>
+ <%= f.submit t('.submit') %>
+ </div>
+ <% end %>
<% end %>
<% content_for :body_content_right do %>