Class/Module Index [+]

Quicksearch

CommentsController

Public Instance Methods

create() click to toggle source

POST /comments POST /comments.json

# File app/controllers/comments_controller.rb, line 47
def create
  params_new= params[:comment].select {|i| !["commentable_id", "commentable_type"].include?(i)}

  c = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? 
  authorize! :comment, c
  
  @comment = Comment.build_for(c, current_user,"", params_new)  
  @commentable=c
  if @comment.parent_object.class==Comment
    @comments= @comment.parent_object.children
  else
    @comments=@comment.parent_object.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order
  end
  respond_to do |format|
    if @comment
      format.js       
    else
      format.js {render action:"new"}
    end
  end
end
destroy() click to toggle source

DELETE /comments/1 DELETE /comments/1.json

# File app/controllers/comments_controller.rb, line 86
def destroy
  @comment = Comment.find(params[:id])
  @commentable=@comment.commentable
  @comment.destroy
  @comments=@commentable.comments.order(:created_at).roots.page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order
  respond_to do |format|
    format.js
  end
end
edit() click to toggle source

GET /comments/1/edit

# File app/controllers/comments_controller.rb, line 41
def edit
  @comment = Comment.find(params[:id])
end
hide() click to toggle source
# File app/controllers/comments_controller.rb, line 16
 def hide
   @commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
   respond_to do |format|
     format.js
   end  
end
index() click to toggle source
# File app/controllers/comments_controller.rb, line 4
  def index
    @commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
if @commentable.nil?
  render status: 404
  else
    @comments=@commentable.comments.order(:created_at).roots.accessible_by(current_ability, :show).page(params[:page]).per(Comment::NUM[params[:commentable_type]]).reverse_order

    respond_to do |format|
      format.js
    end
end
  end
new() click to toggle source
# File app/controllers/comments_controller.rb, line 29
def new
 
  @comment = Comment.new
  @comment.commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil?
  authorize! :comment, @comment.commentable

  respond_to do |format|
    format.js
  end
end
show() click to toggle source
# File app/controllers/comments_controller.rb, line 22
def show
  @comment = Comment.find(params[:id])
  respond_to do |format|
    format.js 
    format.html {redirect_to @comment.commentable}
  end
end
update() click to toggle source

PUT /comments/1 PUT /comments/1.json

# File app/controllers/comments_controller.rb, line 71
def update
  params[:comment].select! {|i| !["commentable_id", "commentable_type"].include?(i)}
  @comment = Comment.find(params[:id])
  @comment.commentable=params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? 
  respond_to do |format|
    if @comment.update_attributes(params[:comment])
      format.html { redirect_to @comment.commentable, notice: 'Comment was successfully updated.' }
    else
      format.html { render action: "edit" }
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.