Class: MongoidForums::TopicsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#destroyObject



21
22
23
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 21

def destroy

end

#my_postsObject



31
32
33
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 31

def my_posts
    @posts = Post.where(:user_id => mongoid_forums_user.id).by_updated_at.page(params[:page]).per(MongoidForums.per_page)
end

#my_subscriptionsObject



25
26
27
28
29
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 25

def my_subscriptions
    @subscriptions = Subscription.where(:subscriber_id => mongoid_forums_user.id, :subscribable_type => "MongoidForums::Topic", :unsubscribed => false).desc(:updated_at)
    @topics = @subscriptions.page(params[:page]).per(MongoidForums.per_page)
    return @topics.sort_by!{:updated_at}
end

#my_topicsObject



35
36
37
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 35

def my_topics
    @topics = Topic.where(:user_id => mongoid_forums_user.id).by_most_recent_post.page(params[:page]).per(MongoidForums.per_page)
end

#showObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 7

def show

  if find_topic
    register_view

    @posts = @topic.posts.order_by([:created_at, :asc])
    @posts = @posts.page(params[:page]).per(MongoidForums.per_page)

    if mongoid_forums_user.present?
      Alert.where(:user_id => mongoid_forums_user.id).update_all(:read => true)
    end
  end
end

#subscribeObject



39
40
41
42
43
44
45
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 39

def subscribe
  if find_topic
    @topic.subscribe_user(mongoid_forums_user.id)
    flash[:notice] = "Successfully subscribed to topic"
    redirect_to topic_url(@topic)
  end
end

#unsubscribeObject



47
48
49
50
51
52
53
# File 'app/controllers/mongoid_forums/topics_controller.rb', line 47

def unsubscribe
  if find_topic
    @topic.unsubscribe_user(mongoid_forums_user.id)
    flash[:notice] = "Successfully unsubscribed to topic"
    redirect_to topic_url(@topic)
  end
end