84 lines
991 B
Ruby
84 lines
991 B
Ruby
# -*- encoding : utf-8 -*-
|
|
|
|
class Admin::ArticlesController < ApplicationController
|
|
|
|
before_filter :authenticate_admin!
|
|
|
|
layout "admin"
|
|
|
|
navigation :articles
|
|
|
|
before_filter :find_articles
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
def cible
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
def new
|
|
|
|
@article = Article.new(:published_at => Time.now)
|
|
|
|
end
|
|
|
|
|
|
def edit
|
|
|
|
@article = Article.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
def create
|
|
|
|
@article = Article.new(params[:article])
|
|
|
|
|
|
if @article.save
|
|
flash[:notice] = "L'article à été ajouté avec succès."
|
|
self.find_articles
|
|
|
|
else
|
|
render :action => "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def update
|
|
|
|
@article = Article.find(params[:id])
|
|
|
|
if @article.update_attributes(params[:article])
|
|
flash[:notice] = "L'article à été modifié avec succès."
|
|
else
|
|
render :action => "edit"
|
|
end
|
|
end
|
|
|
|
|
|
def destroy
|
|
|
|
@article = Article.find(params[:id])
|
|
@article.destroy
|
|
|
|
end
|
|
|
|
protected
|
|
|
|
def find_articles
|
|
|
|
@articles = Article.all
|
|
|
|
end
|
|
|
|
end
|