Class: Back::CategoriesController
- Inherits:
-
BackController
- Object
- BackController
- Back::CategoriesController
- Defined in:
- app/controllers/lato_blog/back/categories_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
This function creates a new category.
-
#destroy ⇒ Object
This function destroyes a category.
-
#edit ⇒ Object
This function show the view to edit a category.
-
#index ⇒ Object
This function shows the list of possible categories.
-
#new ⇒ Object
This function shows the view to create a new category.
-
#show ⇒ Object
This function shows a single category.
-
#update ⇒ Object
This function updates a category.
Instance Method Details
#create ⇒ Object
This function creates a new category.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 39 def create @category = LatoBlog::Category.new(new_category_params) if !@category.save flash[:danger] = @category.errors..to_sentence redirect_to lato_blog.new_category_path return end flash[:success] = LANGUAGES[:lato_blog][:flashes][:category_create_success] redirect_to lato_blog.category_path(@category.id) end |
#destroy ⇒ Object
This function destroyes a category.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 81 def destroy @category = LatoBlog::Category.find_by(id: params[:id]) return unless check_category_presence if !@category.destroy flash[:danger] = @category.category_parent.errors..to_sentence redirect_to lato_blog.edit_category_path(@category.id) return end flash[:success] = LANGUAGES[:lato_blog][:flashes][:category_destroy_success] redirect_to lato_blog.categories_path(status: 'deleted') end |
#edit ⇒ Object
This function show the view to edit a category.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 53 def edit core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories_edit]) @category = LatoBlog::Category.find_by(id: params[:id]) return unless check_category_presence if @category. != [:lato_blog__current_language] set_current_language @category. end fetch_external_objects end |
#index ⇒ Object
This function shows the list of possible categories.
9 10 11 12 13 14 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 9 def index core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories]) # find categories to show @categories = LatoBlog::Category.where(meta_language: [:lato_blog__current_language]).order('title ASC') @widget_index_categories = (@categories, search: 'title', pagination: 10) end |
#new ⇒ Object
This function shows the view to create a new category.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 23 def new core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:categories_new]) @category = LatoBlog::Category.new if params[:language] set_current_language params[:language] end if params[:parent] @category_parent = LatoBlog::CategoryParent.find_by(id: params[:parent]) end fetch_external_objects end |
#show ⇒ Object
This function shows a single category. It create a redirect to the edit path.
17 18 19 20 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 17 def show # use edit as default post show page redirect_to lato_blog.edit_category_path(params[:id]) end |
#update ⇒ Object
This function updates a category.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/lato_blog/back/categories_controller.rb', line 66 def update @category = LatoBlog::Category.find_by(id: params[:id]) return unless check_category_presence if !@category.update(edit_category_params) flash[:danger] = @category.errors..to_sentence redirect_to lato_blog.edit_category_path(@category.id) return end flash[:success] = LANGUAGES[:lato_blog][:flashes][:category_update_success] redirect_to lato_blog.category_path(@category.id) end |