Class: Thredded::TopicsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Thredded::TopicsController
- Defined in:
- app/controllers/thredded/topics_controller.rb
Instance Method Summary collapse
- #category ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
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 = .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) @new_topic.topic if @new_topic.save redirect_to () else render :new end end |
#destroy ⇒ Object
78 79 80 81 82 |
# File 'app/controllers/thredded/topics_controller.rb', line 78 def destroy :destroy, topic topic.destroy! redirect_to (), flash: { notice: 'Topic deleted' } end |
#edit ⇒ Object
69 70 71 |
# File 'app/controllers/thredded/topics_controller.rb', line 69 def edit :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 @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: , user: thredded_current_user) @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], ) @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 :read, topic @posts = topic.posts .includes(:user, :messageboard, :postable) .order('id ASC') .page(current_page) @new_post = .posts.build( postable: topic, filter: .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 (, topic), flash: { notice: 'Topic updated' } end |