Sha256: 5ebb3c3a2e3315fd5f0c0d57a98f60a129586ab69094cfa159fd30ab049b05f6
Contents?: true
Size: 1.59 KB
Versions: 14
Compression:
Stored size: 1.59 KB
Contents
class CommentsController < ApplicationController include Applicat::Mvc::Controller::Resource load_and_authorize_resource before_filter :find_commentable, only: [:new, :edit] respond_to :html, :js, :json def index @comments = Comment.includes(:commentable, :user).all end def show @comment = Comment.includes(:commentable, :user).find(params[:id]) end def new @comment = Comment.new(params[:comment]) @comment.commentable = @commentable end def create @comment = Comment.new(params[:comment]) @comment.user_id = current_user.id if @comment.save redirect_to @comment.commentable, notice: t('general.form.successfully_created') else render :new end end def edit @comment = Comment.find(params[:id]) end def update @comment = Comment.find(params[:id]) if @comment.update_attributes(params[:comment]) redirect_to @comment.commentable, notice: t('general.form.successfully_updated') else render :edit end end def destroy @comment = Comment.find(params[:id]) @comment.destroy redirect_to comments_url, notice: t('general.form.destroyed') end def resource @comment end private def find_commentable @commentable = @comment.commentable ? @comment.commentable : find_parent(Comment::COMMENTABLE_TYPES) eval("@#{@commentable.class.name.tableize.singularize} = @commentable") if @commentable.is_a?(Candidature) @vacancy = @commentable.vacancy elsif @commentable.is_a?(Project) @twitter_sidenav_level = 4 end end end
Version data entries
14 entries across 14 versions & 1 rubygems