<commit_before>class PostsController < ApplicationController

  before_action :get_post_from_id, :except => ['index','new','create']

  # Read
  def index
    @posts = Post.hot
  end

  def show
    @post.view_count += 1
    @post.save
  end

  # Create
  def new
    if enforce_membership
      @post = Post.new
      @post.title = "Untitled Post"
      @post.color = "black"
      @post.author = Member.find(session[:member_id])
    end
  end

  def create
    if enforce_membership
      @post = Post.new(post_params)
      @post.author = Member.find(session[:member_id])
      if @post.save
        redirect_to post_path(@post)
      else
        Rails.logger.debug "Something broke: #{@post.errors.full_messages}"
        render 'new'
      end
    end
  end

  # Update
  def edit
    enforce_post_ownership
  end

  def update
    if enforce_post_ownership
      @post.update(post_params)
      if @post.save
        redirect_to post_path @post
      else
        render 'edit'
      end
    end
  end

  # Delete
  def delete
    enforce_post_ownership
  end

  def destroy
    if enforce_post_ownership
      @post.destroy
      redirect_to posts_path
    end
  end

  private

    def post_params
      params.require('post').permit('title','color','raw_content')
    end

    def get_post_from_id
      @post = Post.find(params[:id])
    end

    def enforce_membership
      if session[:member_id].blank?
        flash['msg'] = "You have to be a Member to perform this action."
        redirect_to posts_path
        return false
      else
        return true
      end
    end<commit_msg>flash feedback on delete and edits<commit_after>class PostsController < ApplicationController

  before_action :get_post_from_id, :except => ['index','new','create']

  # Read
  def index
    @posts = Post.hot
  end

  def show
    @post.view_count += 1
    @post.save
  end

  # Create
  def new
    if enforce_membership
      @post = Post.new
      @post.title = "Untitled Post"
      @post.color = "black"
      @post.author = Member.find(session[:member_id])
    end
  end

  def create
    if enforce_membership
      @post = Post.new(post_params)
      @post.author = Member.find(session[:member_id])
      if @post.save
        redirect_to post_path(@post)
      else
        Rails.logger.debug "Something broke: #{@post.errors.full_messages}"
        render 'new'
      end
    end
  end

  # Update
  def edit
    enforce_post_ownership
  end

  def update
    if enforce_post_ownership
      @post.update(post_params)
      if @post.save
        flash['msg'] = "Your edits were saved."
        redirect_to post_path @post
      else
        render 'edit'
      end
    end
  end

  # Delete
  def delete
    enforce_post_ownership
  end

  def destroy
    if enforce_post_ownership
      flash['msg'] = "Goodbye forever #{@post.title}! We hated you anyway."
      @post.destroy
      redirect_to posts_path
    end
  end

  private

    def post_params
      params.require('post').permit('title','color','raw_content')
    end

    def get_post_from_id
      @post = Post.find(params[:id])
    end

    def enforce_membership
      if session[:member_id].blank?
        flash['msg'] = "You have to be a Member to perform this action."
        redirect_to posts_path
        return false
      else
        return true
      end
    end
{'fraction_non_alphanumeric': 0.08659301283965362, 'fraction_numerical': 0.0005971931919976113, 'mean_word_length': 2.2907662082514735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2537292', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1041, 'n_words': 269}