Class: Shoppy::CategoriesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Shoppy::CategoriesController
- Includes:
- ERB::Util
- Defined in:
- app/controllers/shoppy/categories_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#delete ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/shoppy/categories_controller.rb', line 54 def delete @category = Category.find_by(id: params[:category_id]) if @category @category.destroy Log.newEvent("Categories", "Category named '#{@category.name}' was deleted", current_admin.name) flash[:notice] = "Catgory has been deleted." redirect_to '/products/categories' else page_not_found end end |
#edit ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/shoppy/categories_controller.rb', line 37 def edit @category = Category.find_by(id: params[:category_id]) if @category if @category.update_attributes(category_params) Log.newEvent("Categories", "Category named '#{@category.name}' was updated", current_admin.name) flash[:notice] = "Category has been updated." else flash[:error] = @category.errors. end redirect_to '/products/categories/' + @category.id.to_s else page_not_found end end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/shoppy/categories_controller.rb', line 7 def index @categories = Category.all_sorted end |
#new ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/shoppy/categories_controller.rb', line 11 def new @category = Category.new @category.name = params[:name] if params[:parent_category_id][:id].to_i != 0 @category.parent_category = Category.find((params[:parent_category_id][:id]).to_i) end if @category.save Log.newEvent("Categories", "a new category named '#{@category.name}' was created", current_admin.name) flash[:notice] = "Category has been created." else ## TODO: Handle Errors flash[:error] = @category.errors. end redirect_to '/products/categories' end |
#show ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/controllers/shoppy/categories_controller.rb', line 27 def show c = Category.find_by(id: params[:category_id]) if c @category = c else page_not_found end end |