app/controllers/thredded/topics_controller.rb in thredded-0.11.1 vs app/controllers/thredded/topics_controller.rb in thredded-0.12.0

- old
+ new

@@ -1,12 +1,17 @@ # frozen_string_literal: true module Thredded class TopicsController < Thredded::ApplicationController # rubocop:disable Metrics/ClassLength include Thredded::NewTopicParams + include Thredded::NewPostParams before_action :thredded_require_login!, only: %i(edit new update create destroy follow unfollow) + + before_action :use_topic_messageboard, + only: %i(show edit update destroy follow unfollow) + after_action :update_user_activity after_action :verify_authorized, except: %i(search) after_action :verify_policy_scoped, except: %i(show new create edit update destroy follow unfollow) @@ -41,11 +46,11 @@ Thredded::UserTopicReadState.touch!( thredded_current_user.id, topic.id, page_scope.last, current_page ) end - @new_post = messageboard.posts.build(postable: topic) + @new_post = Thredded::PostForm.new(user: thredded_current_user, topic: topic, post_params: new_post_params) end def search in_messageboard = params.key?(:messageboard_id) if in_messageboard @@ -170,10 +175,16 @@ # If `@topic` is not set, it first sets it to the topic with the slug or ID given by `params[:id]`. # # @return [Thredded::Topic] # @raise [Thredded::Errors::TopicNotFound] if the topic with the given slug does not exist. def topic - @topic ||= messageboard.topics.friendly_find!(params[:id]) + @topic ||= Thredded::Topic.friendly_find!(params[:id]) + end + + # Use the topic's messageboard instead of the one specified in the URL, + # to account for `params[:messageboard_id]` pointing to the wrong messageboard + def use_topic_messageboard + @messageboard = topic.messageboard end def topic_params params .require(:topic)