From f7950e4d9526147177b1244eb51abfea517ab05f Mon Sep 17 00:00:00 2001 From: Alexandr Korol Date: Tue, 17 Feb 2015 18:44:12 +0200 Subject: [PATCH] use before_action --- app/controllers/articles_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 9d7d50d..f818317 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -1,4 +1,5 @@ class ArticlesController < ApplicationController + before_action :set_article, only: [:show, :edit, :update] # before_filter :authenticate_user! respond_to :html @@ -8,7 +9,6 @@ def index end def show - @article = Article.find(params[:id]) @parent = @article @comment = Comment.new end @@ -31,11 +31,9 @@ def create end def edit - @article = Article.find(params[:id]) end def update - @article = Article.find(params[:id]) if @article.update_attributes(article_params) redirect_to article_path, notice: 'The article has been successfully updated.' else @@ -44,8 +42,11 @@ def update end private + def set_acticle + @article = Article.find(params[:id]) + end - def article_params - params.require(:article).permit(:title, :content, :date, :description, :user_id, :cover) - end + def article_params + params.require(:article).permit(:title, :content, :date, :description, :user_id, :cover) + end end