boissier_app/app/controllers/admin/articles_controller.rb
Nicolas Bally 6abf7679fd initial
2011-05-14 13:36:30 +02:00

87 lines
1.6 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::ArticlesController < ApplicationController
before_filter :authenticate_admin!
layout "admin"
navigation :folders
load_and_authorize_resource
def index
@folder = Folder.find(params[:folder_id])
@articles = @folder.articles
if request.xhr?
render :layout => false
end
end
def new
current_navigation :new_articles
@folder = Folder.find(params[:folder_id])
@article = Article.new(:folder => @folder)
end
def create
current_navigation :new_articles
@article = Article.new(params[:article])
@folder = @article.folder
if @article.save
flash[:notice] = "L'article à bien été créé."
respond_to do |format|
format.js
end
else
respond_to do |format|
format.js { render :action => :new}
end
end
end
def edit
current_navigation :edit_articles
@article = Article.find(params[:id])
@folder = @article.folder
end
def update
current_navigation :edit_articles
@article = Article.find(params[:id])
@folder = @article.folder
if @article.update_attributes(params[:article])
flash[:notice] = "Le dossier à bien été modifié."
respond_to do |format|
format.html { redirect_to(admin_articles_path()) }
format.js
end
else
respond_to do |format|
format.html { render :action => :edit}
format.js { render :action => :edit}
end
end
end
def destroy
@article = Article.find(params[:id])
@article.destroy
@folder = @article.folder
flash[:notice] = "L'article à bien été supprimé."
end
end