diff --git a/lib/discourse_topic_voting/categories_controller_extension.rb b/lib/discourse_topic_voting/categories_controller_extension.rb index 34e1bb1..f208dbf 100644 --- a/lib/discourse_topic_voting/categories_controller_extension.rb +++ b/lib/discourse_topic_voting/categories_controller_extension.rb @@ -4,7 +4,7 @@ module DiscourseTopicVoting module CategoriesControllerExtension def category_params @vote_enabled ||= - !!ActiveRecord::Type::Boolean.new.cast(params[:custom_fields][:enable_topic_voting]) + !!ActiveRecord::Type::Boolean.new.cast(params&.[](:custom_fields)&.[](:enable_topic_voting)) category_params = super diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb index f00e387..d8ad13f 100644 --- a/spec/requests/categories_controller_spec.rb +++ b/spec/requests/categories_controller_spec.rb @@ -44,4 +44,9 @@ } expect(Category.can_vote?(category.id)).to eq(false) end + + it "works fine when `custom_fields` isn't passed " do + put "/categories/#{category.id}.json", params: { hello: "world" } + expect(response.status).to eq(200) + end end