| Class | CategoriesController |
| In: |
app/controllers/categories_controller.rb
|
| Parent: | ApplicationController |
File categories_controller.rb Project iboard4 Author Andreas Altendorfer Copyright 2009 by Andreas Altendorfer
Categories can be attached to ‘Categorizables’ (eg. Postings, …)
# File app/controllers/categories_controller.rb, line 35
35: def create
36: params[:category]['permalink_ids'] ||= []
37: @category = Category.new(params[:category])
38: if @category.save
39: flash[:notice] = "Successfully created category."
40: redirect_to @category
41: return false
42: end
43: render :action => 'new'
44: end
# File app/controllers/categories_controller.rb, line 61
61: def destroy
62: @category = Category.find(params[:id])
63: @category.destroy
64: flash[:notice] = "Successfully destroyed category."
65: redirect_to categories_url
66: end
# File app/controllers/categories_controller.rb, line 46
46: def edit
47: @category = Category.find(params[:id])
48: end
# File app/controllers/categories_controller.rb, line 13
13: def index
14: @categories = Category.ascend_by_name.paginate(:page => params[:page], :per_page => POSTINGS_PER_PAGE)
15: end
# File app/controllers/categories_controller.rb, line 31
31: def new
32: @category = Category.new
33: end
Show this category and all records of categorizable models TODO: You have to append new categorizable models like Posting which is the only model yet.
# File app/controllers/categories_controller.rb, line 19
19: def show
20: if params[:id].to_i < 1
21: pl = Permalink.find_by_url(params[:id])
22: @category = pl ? pl.linkable : Category.first
23: else
24: @category = Category.find(params[:id])
25: end
26: # Fetch Postings
27: @items = @category.categorizables.descend_by_updated_at.paginate(:page => params[:page], :per_page => POSTINGS_PER_PAGE)
28: # Append other 'categorizable' models to @items here...
29: end
# File app/controllers/categories_controller.rb, line 50
50: def update
51: params[:category]['permalink_ids'] ||= []
52: @category = Category.find(params[:id])
53: if @category.update_attributes(params[:category])
54: flash[:notice] = "Successfully updated category."
55: redirect_to @category
56: else
57: render :action => 'edit'
58: end
59: end