Sha256: 0de9fb009deeed0f8c4a6cdbcf1a3f665879892d75c6128b7c8c63fcf0897640

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

module Elabs
  class ContentApplicationController < ElabsApplicationController
    DEFAULT_ORDER      = { published_at: :desc }.freeze
    IS_NSFW_FILTERABLE = true

    before_action :new_comment

    # POST /comments
    # POST /comments.json
    def create_comment
      build_comment

      respond_to do |format|
        if @comment.save
          format.html { redirect_to @comment.content, notice: _('Comment was successfully created.') }
          format.json { render :show, status: :created, location: @comment.content }
        else
          @new_comment = @comment
          format.html { redirect_to @comment.content }
          format.json { render json: @comment.errors, status: :unprocessable_entity }
        end
      end
    end

    private

    # Never trust parameters from the scary internet, only allow the white list through.
    def comment_params
      params.require(:comment).permit(:name, :email, :comment, :allow_contact)
    end

    def new_comment
      @new_comment ||= Comment.new
    end

    def build_comment
      @comment = Comment.new(comment_params)
      params.each do |key, value|
        @comment.content_id = value if %w[album_id article_id note_id project_id upload_id].include? key
      end
      @comment.content_type = params[:controller].classify
      @comment.user         = current_user if user_signed_in?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elabs-2.0.0 app/controllers/elabs/content_application_controller.rb
elabs-2.0.0.pre app/controllers/elabs/content_application_controller.rb