Class PostingsController
In: app/controllers/postings_controller.rb
Parent: ApplicationController

File postings_controller.rb Project iboard4 Author Andreas Altendorfer Copyright 2009 by Andreas Altendorfer

Postings belogs to a user and can have one or more categories as a ‘categorizable‘

Methods

create   destroy   edit   index   new   show   update  

Public Instance methods

[Source]

    # File app/controllers/postings_controller.rb, line 49
49:   def create
50:     params[:posting]['category_ids'] ||= []
51:     @posting = Posting.new(params[:posting])
52:     @posting.user ||= current_user
53:     if @posting.save
54:       flash[:notice] = "Successfully created posting."
55:       redirect_to @posting
56:     else
57:       render :action => 'new'
58:     end
59:   end

[Source]

    # File app/controllers/postings_controller.rb, line 76
76:   def destroy
77:     @posting ||= Posting.find(params[:id])
78:     @posting.destroy
79:     flash[:notice] = "Successfully destroyed posting."
80:     redirect_to postings_url
81:   end

[Source]

    # File app/controllers/postings_controller.rb, line 61
61:   def edit
62:     @posting ||= Posting.find(params[:id])
63:   end

If a category_id is given postings are restricted to the given category. If no category_id is given postings are searched with searchlogic

[Source]

    # File app/controllers/postings_controller.rb, line 15
15:   def index
16:     if params[:category_id]
17:       # fetch postings of this category only...
18:       @category = Category.find(params[:category_id])
19:       @postings = @category.categorizables.find_all_by_categorizable_type('Posting').map(&:categorizable).paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
20:     else
21:       # fetch postings of all categories
22:       if params[:user_id]
23:         # fetch postings of the given user only
24:         @user = User.find(params[:user_id])
25:         @postings = @user.postings.descend_by_updated_at.paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
26:       else
27:         # fetch all postings in all categories of each user matching the searchlogic
28:         unless params[:search].blank?
29:           @postings = Posting.subject_like_any_or_body_like_any(
30:                         params[:search].split(/[\s|,]+/)
31:                       ).descend_by_updated_at.paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
32:         else
33:           # fetch ALL postings
34:           @postings = Posting.descend_by_updated_at.paginate( :page => params[:page], :per_page => POSTINGS_PER_PAGE )
35:         end
36:       end
37:     end
38:   end

[Source]

    # File app/controllers/postings_controller.rb, line 45
45:   def new
46:     @posting = Posting.new
47:   end

[Source]

    # File app/controllers/postings_controller.rb, line 41
41:   def show
42:     @posting = Posting.find(params[:id])
43:   end

[Source]

    # File app/controllers/postings_controller.rb, line 65
65:   def update
66:     params[:posting]['category_ids'] ||= []    
67:     @posting ||= Posting.find(params[:id])
68:     if @posting.update_attributes(params[:posting])
69:       flash[:notice] = "Successfully updated posting."
70:       redirect_to @posting
71:     else
72:       render :action => 'edit'
73:     end
74:   end

[Validate]