Class: SimpleForum::PostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/simple_forum/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/simple_forum/posts_controller.rb', line 28

def create
  success = @post.save

  respond_to do |format|
    format.html do
      if success
        redirect_to simple_forum.forum_topic_url(@forum, @topic, :page => @post.on_page, :anchor => "post-#{@post.id}"),
                    :notice => t('simple_forum.controllers.posts.post_created')
      else
        redirect_to simple_forum.forum_topic_url(@forum, @topic, :page => @topic.last_page, :anchor => (@topic.recent_post ? "post-#{@topic.recent_post.id}" : nil)),
                    :alert => @post.errors.full_messages.join(', ')
      end
    end
  end
end

#deleteObject



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/simple_forum/posts_controller.rb', line 75

def delete
  success = @post.mark_as_deleted_by(authenticated_user) #check if post is deletable by authenticated_user in mark_as_deleted_by method

  respond_to do |format|
    format.html do
      if success
        redirect_to :back, :notice => t('simple_forum.controllers.posts.post_deleted')
      else
        redirect_to :back, :alert => t('simple_forum.controllers.posts.post_cant_be_deleted')
      end
    end
  end
end

#editObject



52
53
54
55
# File 'app/controllers/simple_forum/posts_controller.rb', line 52

def edit

  respond_to :html
end

#indexObject



12
13
14
15
16
17
18
19
# File 'app/controllers/simple_forum/posts_controller.rb', line 12

def index

  respond_to do |format|
    format.html do
      redirect_to simple_forum.forum_topic_url(@forum, @topic), :status => :moved_permanently
    end
  end
end

#previewObject



44
45
46
47
48
49
50
# File 'app/controllers/simple_forum/posts_controller.rb', line 44

def preview
  @post.created_at, @post.updated_at = Time.now

  respond_to do |format|
    format.js { render :partial => 'simple_forum/topics/post', :locals => {:post => @post, :preview => true} }
  end
end

#showObject



21
22
23
24
25
26
# File 'app/controllers/simple_forum/posts_controller.rb', line 21

def show

  respond_to do |format|
    format.html { redirect_to simple_forum.forum_topic_url(@forum, @topic, :page => @post.on_page, :anchor => "post-#{@post.id}") }
  end
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/simple_forum/posts_controller.rb', line 57

def update
  @post.edited_by = authenticated_user
  @post.edited_at = Time.now
  success = @post.update_attributes(params[:post])

  respond_to do |format|
    format.html do
      if success
        redirect_to simple_forum.forum_topic_url(@forum, @topic, :page => @post.on_page, :anchor => "post-#{@post.id}"),
                    :notice => t('simple_forum.controllers.posts.post_updated')
      else
        redirect_to :back, :alert => @post.errors.full_messages.join(', ')
      end
    end
  end
end