Refactored article_categories.

This commit is contained in:
benni 2011-05-18 16:10:30 +02:00
parent 0b1682af7c
commit 0decbb36e1
12 changed files with 39 additions and 118 deletions

View file

@ -1,71 +1,15 @@
class ArticleCategoriesController < ApplicationController
inherit_resources # Build default REST Actions via plugin
before_filter :authenticate_article_meta
def index
@article_categories = ArticleCategory.all :order => 'name'
end
def new
@article_category = ArticleCategory.new
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
page['category_form'].show
end
end
def edit
@article_category = ArticleCategory.find(params[:id])
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
page['category_form'].show
end
end
def create
@article_category = ArticleCategory.new(params[:article_category])
if @article_category.save
render :update do |page|
page['category_form'].hide
page['category_list'].replace_html :partial => 'article_categories/list'
page['category_'+@article_category.id.to_s].visual_effect(:highlight,
:duration => 2)
end
else
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
end
end
create!(:notice => "Die Kategorie wurde gespeichert") { article_categories_path }
end
def update
@article_category = ArticleCategory.find(params[:id])
if @article_category.update_attributes(params[:article_category])
render :update do |page|
page['category_form'].hide
page['category_list'].replace_html :partial => 'article_categories/list'
page['category_'+@article_category.id.to_s].visual_effect(:highlight,
:duration => 2)
end
else
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
end
end
update!(:notice => "Die Kategorie wurde aktualisiert") { article_categories_path }
end
def destroy
@article_category = ArticleCategory.find(params[:id])
@article_category.destroy
if @article_category.destroy
render :update do |page|
page['category_'+@article_category.id.to_s].visual_effect :drop_out
end
end
end
end

View file

@ -28,8 +28,8 @@ class ArticlesController < ApplicationController
# if somebody uses the search field:
conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
@total = @supplier.articles.without_deleted.count(:conditions => conditions)
@articles = @supplier.articles.without_deleted.paginate(
@total = @supplier.articles.count(:conditions => conditions)
@articles = @supplier.articles.paginate(
:order => sort,
:conditions => conditions,
:page => params[:page],