Merge pull request #1920 from nickborromeo/list-controller

Extract queries to keep logic in the Categories Model
This commit is contained in:
Robin Ward
2014-02-11 15:48:20 -05:00
3 changed files with 28 additions and 4 deletions

View File

@ -219,13 +219,12 @@ class ListController < ApplicationController
parent_category_id = nil
if parent_slug_or_id.present?
parent_category_id = Category.where(slug: parent_slug_or_id).pluck(:id).first ||
Category.where(id: parent_slug_or_id.to_i).pluck(:id).first
parent_category_id = Category.query_parent_category(parent_slug_or_id)
raise Discourse::NotFound.new if parent_category_id.blank?
end
@category = Category.where(slug: slug_or_id, parent_category_id: parent_category_id).includes(:featured_users).first ||
Category.where(id: slug_or_id.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
@category = Category.query_category(slug_or_id, parent_category_id)
guardian.ensure_can_see!(@category)
raise Discourse::NotFound.new if @category.blank?