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



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

def destroy

end

#my_postsObject



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

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



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

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



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

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
# 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, read: false, subscription_id: Subscription.where(subscribable_id: @topic.id, subscriber_id: mongoid_forums_user.id).first).update_all(:read => true, :ready_at => Time.now)
    end
  end
end

#subscribeObject



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

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

#unsubscribeObject



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

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