Class: Postnhost::CategoriesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Postnhost::CategoriesController
- Defined in:
- app/controllers/postnhost/categories_controller.rb
Constant Summary collapse
- PAGE_SIZE =
15
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/postnhost/categories_controller.rb', line 25 def create @category = Postnhost::Category.new @category.assign_attributes(category_params) if @category.save redirect_to categories_url else render :new, status: :unprocessable_content end end |
#destroy ⇒ Object
44 45 46 47 |
# File 'app/controllers/postnhost/categories_controller.rb', line 44 def destroy @category.destroy redirect_to categories_url, notice: "Category was successfully deleted." end |
#edit ⇒ Object
23 |
# File 'app/controllers/postnhost/categories_controller.rb', line 23 def edit; end |
#index ⇒ Object
10 11 12 |
# File 'app/controllers/postnhost/categories_controller.rb', line 10 def index @categories = Postnhost::Category.order(updated_at: :desc) end |
#new ⇒ Object
19 20 21 |
# File 'app/controllers/postnhost/categories_controller.rb', line 19 def new @category = Postnhost::Category.new end |
#show ⇒ Object
14 15 16 17 |
# File 'app/controllers/postnhost/categories_controller.rb', line 14 def show articles = @category.articles.includes(:article_snapshot, :language).order(created_at: :desc) @pagy, @articles = pagy(:offset, articles, limit: PAGE_SIZE) end |
#update ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/controllers/postnhost/categories_controller.rb', line 36 def update if @category.update(category_params) redirect_to @category, notice: "Category was successfully updated." else render :edit, status: :unprocessable_content end end |