diff --git a/app/controllers/alt_styles_controller.rb b/app/controllers/alt_styles_controller.rb index 2f4a6b57..46f9f7fd 100644 --- a/app/controllers/alt_styles_controller.rb +++ b/app/controllers/alt_styles_controller.rb @@ -1,6 +1,16 @@ class AltStylesController < ApplicationController def index @alt_styles = AltStyle.includes(:species, :color, :swf_assets). - order(:species_id, :color_id).all + order(:species_id, :color_id) + + if params[:species_id] + @species = Species.find(params[:species_id]) + @alt_styles = @alt_styles.merge(@species.alt_styles) + end + + respond_to do |format| + format.html { render } + format.json { render json: @alt_styles } + end end end diff --git a/app/models/species.rb b/app/models/species.rb index f6f08e18..f8de694c 100644 --- a/app/models/species.rb +++ b/app/models/species.rb @@ -1,6 +1,7 @@ class Species < ApplicationRecord translates # TODO: Remove once we're all done with translations! has_many :pet_types + has_many :alt_styles scope :alphabetical, -> { order(:name) } diff --git a/config/routes.rb b/config/routes.rb index 99912fb3..d7bf4e29 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,7 @@ OpenneoImpressItems::Application.routes.draw do resources :colors, only: [] do get :pet_type, to: 'pet_types#show' end + resources :alt_styles, path: 'alt-styles', only: [:index] end resources :colors, only: [] do resources :pet_types, only: [:index]