Class: MongoidForums::ForumsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mongoid_forums/forums_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#createObject

Note: This is not an action to make a new Forum! it is to create a new TOPIC within a forum


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/mongoid_forums/forums_controller.rb', line 32

def create
  @forum = Forum.find(params[:forum_id])
  authorize! :create_topic, @forum

  @topic = Topic.new
  @topic.name = topic_params[:name]
  @topic.user = mongoid_forums_user.id
  @topic.forum = @forum.id
  @post = Post.new
  @post.user = mongoid_forums_user.id
  @post.text = topic_params[:posts][:text]
  @topic.posts << @post

  if @topic.save && @topic.posts.first.save
    flash[:notice] = t("mongoid_forums.topic.created")
    redirect_to @topic
  else
    flash.now.alert = t("mongoid_forums.topic.not_created")
    render :action => "new"
  end
end

#indexObject


8
9
10
# File 'app/controllers/mongoid_forums/forums_controller.rb', line 8

def index
  @categories = Category.asc(:position)
end

#newObject

Note: This is not an action to make a new Forum! it is to create a new TOPIC within a forum


22
23
24
25
26
27
28
# File 'app/controllers/mongoid_forums/forums_controller.rb', line 22

def new
  @forum = Forum.find(params[:forum_id])
  authorize! :create_topic, @forum

  @topic = Topic.new
  @topic.forum = @forum.id
end

#showObject


12
13
14
15
16
17
18
# File 'app/controllers/mongoid_forums/forums_controller.rb', line 12

def show
  @forum = Forum.find(params[:id])
  register_view

  @topics = @forum.topics
  @topics = @topics.by_pinned_or_most_recent_post.page(params[:page]).per(MongoidForums.per_page)
end