Class: Admin::CategoriesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Admin::CategoriesController
- Defined in:
- app/controllers/admin/categories_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #sort ⇒ Object
- #sorting ⇒ Object
- #update ⇒ Object
Methods inherited from BaseController
Methods included from BaseHelper
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/admin/categories_controller.rb', line 19 def create @category = Category.new(params[:category]) if @category.save redirect_to admin_categories_path else render :new end end |
#destroy ⇒ Object
41 42 43 44 45 |
# File 'app/controllers/admin/categories_controller.rb', line 41 def destroy @category = Category.find(params[:id]) @category.destroy redirect_to admin_categories_path end |
#edit ⇒ Object
28 29 30 |
# File 'app/controllers/admin/categories_controller.rb', line 28 def edit @category = Category.find(params[:id]) end |
#index ⇒ Object
11 12 13 |
# File 'app/controllers/admin/categories_controller.rb', line 11 def index @categories = Category.arrange end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/admin/categories_controller.rb', line 15 def new @category = Category.new end |
#sort ⇒ Object
47 48 49 50 |
# File 'app/controllers/admin/categories_controller.rb', line 47 def sort @category = Category.find(params[:id]) @categories = @category.children_by_position end |
#sorting ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/admin/categories_controller.rb', line 52 def sorting categories = Category.find(params[:category]) categories.each do |category| category.position = params[:category].index(category.id.to_s)+1 category.save end render :nothing => true end |
#update ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'app/controllers/admin/categories_controller.rb', line 32 def update @category = Category.find(params[:id]) if @category.update_attributes(params[:category]) redirect_to admin_categories_path else render :edit end end |