| Class | PagesController |
| In: |
app/controllers/pages_controller.rb
|
| Parent: | ApplicationController |
# File app/controllers/pages_controller.rb, line 45
45: def create
46: params[:page]['category_ids'] ||= []
47: params[:page]['permalink_ids'] ||= []
48: @page = Page.new(params[:page])
49: @page.user ||= current_user
50: if @page.save
51: flash[:notice] = "Successfully created posting."
52: redirect_to @page
53: else
54: render :action => 'new'
55: end
56: end
# File app/controllers/pages_controller.rb, line 74
74: def destroy
75: @page = Page.find(params[:id])
76: @page.destroy
77: flash[:notice] = "Successfully destroyed page."
78: redirect_to pages_url
79: end
# File app/controllers/pages_controller.rb, line 58
58: def edit
59: @page = Page.find(params[:id])
60: end
# File app/controllers/pages_controller.rb, line 6
6: def index
7: if params[:category_id]
8: # fetch postings of this category only...
9: @category = Category.find(params[:category_id])
10: @pages = @category.categorizables.find_all_by_categorizable_type('Page').map(&:categorizable).paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
11: else
12: # fetch postings of all categories
13: if params[:user_id]
14: # fetch postings of the given user only
15: @user = User.find(params[:user_id])
16: @pages = @user.pages.descend_by_updated_at.paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
17: else
18: # fetch all postings in all categories of each user matching the searchlogic
19: unless params[:search].blank?
20: @pages = Page.title_like_any_or_description_like_any_or_body_like_any(
21: params[:search].split(/[\s|,]+/)
22: ).descend_by_updated_at.paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
23: else
24: # fetch ALL postings
25: @pages = Page.descend_by_updated_at.paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
26: end
27: end
28: end
29: end
# File app/controllers/pages_controller.rb, line 31
31: def show
32: if params[:id].to_i < 1
33: pl = Permalink.find_by_url(params[:id])
34: @page = pl ? pl.linkable : Page.first
35: else
36: @page = Page.find(params[:id])
37: end
38: @page.revert_to(params[:version].to_i) if params[:version]
39: end
# File app/controllers/pages_controller.rb, line 62
62: def update
63: params[:page]['category_ids'] ||= []
64: params[:page]['permalink_ids'] ||= []
65: @page ||= Page.find(params[:id])
66: if @page.update_attributes(params[:page])
67: flash[:notice] = "Successfully updated posting."
68: redirect_to @page
69: else
70: render :action => 'edit'
71: end
72: end