Skip to content

Instantly share code, notes, and snippets.

@fabiosussetto
Created July 11, 2011 20:44
Show Gist options
  • Save fabiosussetto/1076759 to your computer and use it in GitHub Desktop.
Save fabiosussetto/1076759 to your computer and use it in GitHub Desktop.
#publications_controller
def show
@comments = @publication.comments.includes(:author => :user).order('created_at desc').page(params[:page]).per(10)
@comment = @publication.comments.build
end
#comments_controller
def create
@publication = Publication.find(params[:publication_id])
@comment = @publication.comments.new(params[:comment])
@comment.author = current_user.accountable
authorize! :create, @comment
if @comment.save
redirect_to institute_publication_url(current_institute, @publication), :notice => "Successfully created comment."
else
@comments = @publication.comments.includes(:author => :user).order('created_at desc').page(params[:page]).per(10)
render :template => "publications/show"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment