Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove little duplication
  • Loading branch information
Yannick Francois committed Aug 5, 2013
1 parent 86e6074 commit c6f3a1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
8 changes: 8 additions & 0 deletions app/controllers/admin/base_controller.rb
Expand Up @@ -16,6 +16,14 @@ def insert_editor
end

private

def destroy_a(klass_to_destroy)
@record = klass_to_destroy.find(params[:id])
return render('admin/shared/destroy') unless request.post?
@record.destroy
redirect_to action: 'index'
end

def look_for_needed_db_updates
migrator = Migrator.new
if migrator.migrations_pending?
Expand Down
12 changes: 4 additions & 8 deletions app/controllers/admin/categories_controller.rb
Expand Up @@ -4,21 +4,17 @@ class Admin::CategoriesController < Admin::BaseController
def index; redirect_to :action => 'new' ; end
def edit; new_or_edit; end

def new
def new
respond_to do |format|
format.html { new_or_edit }
format.js {
format.js {
@category = Category.new
}
end
end

def destroy
@record = Category.find(params[:id])
return(render 'admin/shared/destroy') unless request.post?

@record.destroy
redirect_to :action => 'new'
destroy_a(Category)
end

private
Expand All @@ -35,7 +31,7 @@ def new_or_edit
if request.post?
respond_to do |format|
format.html { save_category }
format.js do
format.js do
@category.save
@article = Article.new
@article.categories << @category
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/admin/pages_controller.rb
Expand Up @@ -39,10 +39,7 @@ def edit
end

def destroy
@record = Page.find(params[:id])
return(render 'admin/shared/destroy') unless request.post?
@record.destroy
redirect_to :action => 'index'
destroy_a(Page)
end

private
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/admin/tags_controller.rb
Expand Up @@ -23,11 +23,7 @@ def edit
end

def destroy
@record = Tag.find(params[:id])
return(render 'admin/shared/destroy') unless request.post?

@record.destroy
redirect_to :action => 'index'
destroy_a(Tag)
end

end

0 comments on commit c6f3a1c

Please sign in to comment.