Class: Parrot::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/parrot/comments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#default_url_options

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/parrot/comments_controller.rb', line 15

def create
  @comment = Comment.new(params[:parrot_comment])
  @comment.commentable_type = commentable_type
  @comment.commentable_id = commentable_id
  @comment.author_id = current_user.id
  @commentable_type = commentable_type
  if @comment.save
    flash[:notice] = t('flash.actions.create.notice', resource_name: t('activerecord.models.comment'))
    redirect_to after_comment_path(commentable, @comment)
  else
    flash[:notice] = t('flash.actions.create.alert', resource_name: t('activerecord.models.comment'))
    redirect_to :back
  end
end

#destroyObject



30
31
32
33
34
35
# File 'app/controllers/parrot/comments_controller.rb', line 30

def destroy
  @comment = current_user.comments.find params[:id]
  @comment.destroy
  params[:commentable_type] = @comment.commentable_type # Set commentable_type param (maybe namespaced for example)
  respond_with @comment, :location => after_comment_path(commentable, @comment)
end

#indexObject



5
6
7
8
# File 'app/controllers/parrot/comments_controller.rb', line 5

def index
  @comments = Comment.where(commentable_type: commentable_type, commentable_id: commentable_id)
  respond_with @comments
end

#newObject



10
11
12
13
# File 'app/controllers/parrot/comments_controller.rb', line 10

def new
  @comment = Comment.new
  respond_with @comment
end