Class: Thredded::TopicsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#signed_in?

Instance Method Details

#category ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/thredded/topics_controller.rb', line 45

def category
  @category = messageboard.categories.friendly.find(params[:category_id])
  @topics = @category
    .topics
    .unstuck
    .order_by_updated_time
    .on_page(current_page)
    .load
  @decorated_topics = Thredded::UserTopicDecorator
    .decorate_all(thredded_current_user, @topics)

  render :index
end

#create ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'app/controllers/thredded/topics_controller.rb', line 59

def create
  @new_topic = TopicForm.new(new_topic_params)
  authorize_creating @new_topic.topic
  if @new_topic.save
    redirect_to messageboard_topics_path(messageboard)
  else
    render :new
  end
end

#destroy ⇒ Object



78
79
80
81
82
# File 'app/controllers/thredded/topics_controller.rb', line 78

def destroy
  authorize! :destroy, topic
  topic.destroy!
  redirect_to messageboard_topics_path(messageboard), flash: { notice: 'Topic deleted' }
end

#edit ⇒ Object



69
70
71
# File 'app/controllers/thredded/topics_controller.rb', line 69

def edit
  authorize! :update, topic
end

#index ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/thredded/topics_controller.rb', line 6

def index
  authorize_reading messageboard

  @topics = topics
  @decorated_topics = Thredded::UserTopicDecorator
    .decorate_all(thredded_current_user, @topics)
  initialize_new_topic.tap do |new_topic|
    @new_topic = new_topic if current_ability.can?(:create, new_topic.topic)
  end
end

#new ⇒ Object



40
41
42
43
# File 'app/controllers/thredded/topics_controller.rb', line 40

def new
  @new_topic = TopicForm.new(messageboard: messageboard, user: thredded_current_user)
  authorize_creating @new_topic.topic
end

#search ⇒ Object



33
34
35
36
37
38
# File 'app/controllers/thredded/topics_controller.rb', line 33

def search
  @topics = Topic.search(params[:q], messageboard)
  @decorated_topics = Thredded::UserTopicDecorator
    .decorate_all(thredded_current_user, @topics)
  flash.now[:notice] = "Search Results for '#{params[:q]}'"
end

#show ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/thredded/topics_controller.rb', line 17

def show
  authorize! :read, topic

  @posts = topic.posts
    .includes(:user, :messageboard, :postable)
    .order('id ASC')
    .page(current_page)

  @new_post = messageboard.posts.build(
    postable: topic,
    filter: messageboard.filter
  )

  update_read_status
end

#update ⇒ Object



73
74
75
76
# File 'app/controllers/thredded/topics_controller.rb', line 73

def update
  topic.update_attributes!(topic_params.merge(last_user_id: thredded_current_user.id))
  redirect_to messageboard_topic_posts_url(messageboard, topic), flash: { notice: 'Topic updated' }
end