Class: Formol::PostsController

Inherits:
ApplicationController show all
Includes:
Controllers::Nested::HasParentTopic
Defined in:
app/controllers/formol/posts_controller.rb

Instance Method Summary collapse

Methods included from Controllers::Nested::HasParentTopic

#topic

Methods inherited from ApplicationController

#last_page_forum_topic_path, #paginated_forum_topic_post_path, #per_page, #topic_last_page_number, #topic_post_page_number

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/formol/posts_controller.rb', line 24

def create
  formol_authorize!(current_formol_user, :create_post, topic)
  
  post(:user => current_formol_user)
  
  if post.save
    #post.topic(true) needed to handle counter increment
    respond_with(post, :status => :created, :location => last_page_forum_topic_path(topic.forum, post.topic(true), post))
  else
    respond_with(post, :status => :unprocessable_entity) do |format|
      format.html { render :new }
    end
  end
end

#destroyObject



57
58
59
60
61
62
63
# File 'app/controllers/formol/posts_controller.rb', line 57

def destroy
  formol_authorize!(current_formol_user, :destroy_post)
  
  post.destroy
  
  respond_with(post, :location => [topic.forum, topic])
end

#editObject



39
40
41
42
43
# File 'app/controllers/formol/posts_controller.rb', line 39

def edit
  formol_authorize!(current_formol_user, :edit_post, post)
  
  post
end

#newObject



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

def new
  formol_authorize!(current_formol_user, :create_post, topic)
  
  post(:quote_id => params[:quote], :user => current_formol_user)
end

#showObject



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

def show
  formol_authorize!(current_formol_user, :read_topic)
  
  post
  
  #respond_with location doesn't work here :/
  respond_with(post) do |format|
    format.html { redirect_to paginated_forum_topic_post_path(post.topic.forum, post.topic, post) }
  end
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/formol/posts_controller.rb', line 45

def update
  formol_authorize!(current_formol_user, :edit_post, post)
  
  if post.update_attributes(params[:post])
    respond_with(post, :location => paginated_forum_topic_post_path(topic.forum, topic, post))
  else
    respond_with(post) do |format|
      format.html { render :edit }
    end
  end
end