class ArticlesController < ApplicationController

  def index
    @articles = Article.all
  end

  def show
    @article = Article.find(params[:id])
  end
  
  def new
  end

  def create
    @article = Article.new(article_params)

    if @article.valid?
      @article.save
      redirect_to @article
    else
      render action: 'new'
    end
  end

  def edit
    @article = Article.find(params[:id])
  end

  def update
    @article = Article.find(params[:id])
    
    if @article.update(article_params)
      redirect_to @article
    else
      render action: 'edit'
    end
  end

  def destroy
    @article = Article.find(params[:id])
    
    @article.destroy
    redirect_to articles_path
  end

  private

  def article_params # allowing attributes from params[]
    params.require(:article).permit(:title, :text)
  end

end

class ArticlesController < ApplicationController

  before_filter :authenticate_user!

  def index
    @articles = Article.all
  end

  def show
    @article = Article.find(params[:id])
  end
  
  def new
  end

  def create
    @article = Article.new(article_params)

    if @article.valid?
      @article.save
      redirect_to @article
    else
      render action: 'new'
    end
  end

  def edit
    @article = Article.find(params[:id])
  end

  def update
    @article = Article.find(params[:id])
    
    if @article.update(article_params)
      redirect_to @article
    else
      render action: 'edit'
    end
  end

  def destroy
    @article = Article.find(params[:id])
    
    @article.destroy
    redirect_to articles_path
  end

  private

  def article_params # allowing attributes from params[]
    params.require(:article).permit(:title, :text)
  end

end

Add user authentification on controller 'articles'
Add user authentification on controller 'articles'
