Class: Gluttonberg::Public::CommentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/gluttonberg/public/comments_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#locale, #page

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/gluttonberg/public/comments_controller.rb', line 5

def create
  @blog = Gluttonberg::Blog.first(:conditions => {:slug => params[:blog_id]})
  @article = Gluttonberg::Article.first(:conditions => {:slug => params[:article_id], :blog_id => @blog.id})
  @comment = @article.comments.new(params[:comment].merge(:blog_slug => params[:blog_id]))
  @comment.author_id = current_member.id if current_member
  if @comment.save
    if Setting.get_setting("comment_notification") == "Yes" || @blog.moderation_required == true
      User.all_super_admin_and_admins.each do |user|
        Notifier.comment_notification_for_admin(user , @article , @comment).deliver
      end
    end
    
    @subscription = CommentSubscription.find(:first , :conditions => {:article_id => @article.id , :author_email => @comment.writer_email })
    if @comment.subscribe_to_comments == "1" && @subscription.blank?
      @subscription = CommentSubscription.create( {:article_id => @article.id , :author_email => @comment.writer_email , :author_name => @comment.writer_name } )
    elsif (@comment.subscribe_to_comments.blank? || @comment.subscribe_to_comments == "0")  && !@subscription.blank?
      #unsubscribe
      @subscription.destroy 
    end
  else
    
  end
  if Gluttonberg.localized?
    redirect_to blog_article_path(current_localization_slug , @blog.slug, @article.slug)
  else
    redirect_to blog_article_path(:blog_id =>  @blog.slug, :id => @article.slug)
  end
end