Class: Formol::TopicsController

Inherits:
ApplicationController show all
Includes:
Controllers::Nested::HasParentForum
Defined in:
app/controllers/formol/topics_controller.rb

Instance Method Summary collapse

Methods included from Controllers::Nested::HasParentForum

#forum

Methods inherited from ApplicationController

#last_page_forum_topic_path, #paginated_forum_topic_post_path, #per_page, #topic_last_page_number, #topic_post_page_number

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/formol/topics_controller.rb', line 31

def create
  formol_authorize!(current_formol_user, :create_topic)
  
  topic.user = current_formol_user
  
  if topic.save
    respond_with(topic, :location => [forum, topic])
  else
    unless topic.poll
      topic.build_poll
      topic.poll.options.build
    end
    
    respond_with(topic, :status => :unprocessable_entity) do |format|
      format.html { render :new }
    end
  end
end

#destroyObject



68
69
70
71
72
73
74
# File 'app/controllers/formol/topics_controller.rb', line 68

def destroy
  formol_authorize!(current_formol_user, :destroy_topic)
  
  topic.destroy
  
  respond_with(topic, :location => forum)
end

#editObject



50
51
52
53
54
# File 'app/controllers/formol/topics_controller.rb', line 50

def edit
  formol_authorize!(current_formol_user, :edit_topic, topic)
  
  respond_with(topic)
end

#lockObject



92
93
94
95
96
97
98
# File 'app/controllers/formol/topics_controller.rb', line 92

def lock
  formol_authorize!(current_formol_user, :lock_topic)
  
  topic.lock_topic!
  
  respond_with(topic, :location => [forum, topic])
end

#newObject



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

def new
  formol_authorize!(current_formol_user, :create_topic)
  
  topic.posts.build(:register_user_as_subscriber => true)
  
  unless topic.poll
    topic.build_poll
    topic.poll.options.build
  end
  
  respond_with(topic)
end

#pinObject



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

def pin
  formol_authorize!(current_formol_user, :pin_topic)
  
  topic.pin_topic!
  
  respond_with(topic, :location => [forum, topic])
end

#showObject



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

def show
  formol_authorize!(current_formol_user, :read_topic)
  
  topic.view!
  topic.track_for_user!(current_formol_user)
    
  @posts = topic.posts.ready_for_listing.page(params[:page]).per_page(per_page)
  
  respond_with(topic)
end

#unlockObject



100
101
102
103
104
105
106
# File 'app/controllers/formol/topics_controller.rb', line 100

def unlock
  formol_authorize!(current_formol_user, :lock_topic)
  
  topic.unlock_topic!
  
  respond_with(topic, :location => [forum, topic])
end

#unpinObject



84
85
86
87
88
89
90
# File 'app/controllers/formol/topics_controller.rb', line 84

def unpin
  formol_authorize!(current_formol_user, :pin_topic)
  
  topic.unpin_topic!
  
  respond_with(topic, :location => [forum, topic])
end

#updateObject



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/formol/topics_controller.rb', line 56

def update
  formol_authorize!(current_formol_user, :edit_topic, topic)
  
  if topic.update_attributes(params[:topic])
    respond_with(topic, :location => [forum, topic])
  else 
    respond_with(topic) do |format|
      format.html { render :edit }
    end
  end
end