Class: Forge::PostsController

Inherits:
ForgeController show all
Defined in:
lib/forge/app/controllers/forge/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ForgeController

#get_menu_items, #load_help, #set_crumbs, #set_title, #uses_ckeditor

Methods inherited from ApplicationController

#app_init

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 36

def create
  @post = Post.new(params[:post])

  respond_to do |format|
    if @post.save
      format.html { redirect_to(forge_posts_path, :notice => 'Post was successfully created.') }
      format.xml  { render :xml => @post, :status => :created, :location => @post }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @post.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



63
64
65
66
67
68
69
70
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 63

def destroy
  @post.destroy

  respond_to do |format|
    format.html { redirect_to(forge_posts_path) }
    format.xml  { head :ok }
  end
end

#editObject



33
34
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 33

def edit
end

#indexObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 6

def index
  respond_to do |format|
    format.html { @posts = Post.paginate(:per_page => 10, :page => params[:page]) }
    format.js  {
      params[:q] ||= ''
      @posts = Post.where("LOWER(title) LIKE :q OR LOWER(content) LIKE :q", {:q => "%#{params[:q].downcase}%"})
      render :partial => "post", :collection => @posts
    }
  end
end

#newObject



24
25
26
27
28
29
30
31
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 24

def new
  @post = Post.new
  @help = HelpTopic.where(:slug => "posts_new").first
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @post }
  end
end

#showObject



17
18
19
20
21
22
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 17

def show
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @post }
  end
end

#updateObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/forge/app/controllers/forge/posts_controller.rb', line 50

def update
  params[:post][:post_category_ids] ||= []
  respond_to do |format|
    if @post.update_attributes(params[:post])
      format.html { redirect_to(forge_posts_path, :notice => 'Post was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @post.errors, :status => :unprocessable_entity }
    end
  end
end