view .svn/pristine/0f/0f71516e3a6532ada8045e94e42972a11451afc4.svn-base @ 1080:5bd8c86cfa6a issue_540

Makes the Publication model act as an activity; overloading the default ActivitiesController#index view in the Bibliography Plugin in order to differentiate Publications from the other event types. * Known issues: ** route to /activities is not working (only to /activity); ** publication cache needs to be implemented in the model, not in the helper; ** when a publication is added to n projects, n events are created (all with the same content).
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 22 Nov 2012 16:51:23 +0000
parents cbb26bc654de
children
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(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