view app/controllers/comments_controller.rb @ 947:be4106d14a35 bibplugin_bibtex

Parses a pasted bibtex entry and correctly adds its fields *except* the author names/institutions. Todo: Parse the author names/institutions and show the errors (flashing on the top of the page).
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 18 Jul 2012 16:57:54 +0100
parents 5f33065ddc4b
children 433d4f72a19b
line wrap: on
line source
class CommentsController < ApplicationController
  default_search_scope :news
  model_object News
  before_filter :find_model_object
  before_filter :find_project_from_association
  before_filter :authorize

  verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
  def create
    @comment = Comment.new
    @comment.safe_attributes = params[:comment]
    @comment.author = User.current
    if @news.comments << @comment
      flash[:notice] = l(:label_comment_added)
    end

    redirect_to :controller => 'news', :action => 'show', :id => @news
  end

  verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
  def destroy
    @news.comments.find(params[:comment_id]).destroy
    redirect_to :controller => 'news', :action => 'show', :id => @news
  end

  private

  # ApplicationController's find_model_object sets it based on the controller
  # name so it needs to be overriden and set to @news instead
  def find_model_object
    super
    @news = @object
    @comment = nil
    @news
  end

end