class Admin::ArticleController < ApplicationController before_action :authenticate_admin! layout 'admin' def index @articles = Article.all end def show @article = Article.find(params[:id]) @all_pages = AllPage.where('article_id = ? AND type_of = 3', @article.id).order('updated_at DESC') end def new @article = Article.new end def create @article = Article.new(articles_params) if @article.save respond_to do |format| format.html {redirect_to action: 'index'} format.js {@articles = Article.all} end else render 'new' end end def edit @article = Article.find(params[:id]) end def update @article = Article.find(params[:id]) if @article.update_attributes(articles_params) respond_to do |format| format.html {redirect_to action: 'index'} format.js {@articles = Article.all} end else render 'edit' end end def destroy @article = Article.find(params[:id]) unless @article.blank? @article.destroy end redirect_to action: 'index' end protected def articles_params params.require(:article).permit(:name) end end