forked from OpenNeo/impress
API endpoints to load alt styles as JSON, and filter by species
Gonna use this in the app for the alt style picker! Still deciding on the UI details.
This commit is contained in:
parent
6763e9454e
commit
72d4bc65ae
3 changed files with 13 additions and 1 deletions
|
@ -1,6 +1,16 @@
|
||||||
class AltStylesController < ApplicationController
|
class AltStylesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@alt_styles = AltStyle.includes(:species, :color, :swf_assets).
|
@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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Species < ApplicationRecord
|
class Species < ApplicationRecord
|
||||||
translates # TODO: Remove once we're all done with translations!
|
translates # TODO: Remove once we're all done with translations!
|
||||||
has_many :pet_types
|
has_many :pet_types
|
||||||
|
has_many :alt_styles
|
||||||
|
|
||||||
scope :alphabetical, -> { order(:name) }
|
scope :alphabetical, -> { order(:name) }
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ OpenneoImpressItems::Application.routes.draw do
|
||||||
resources :colors, only: [] do
|
resources :colors, only: [] do
|
||||||
get :pet_type, to: 'pet_types#show'
|
get :pet_type, to: 'pet_types#show'
|
||||||
end
|
end
|
||||||
|
resources :alt_styles, path: 'alt-styles', only: [:index]
|
||||||
end
|
end
|
||||||
resources :colors, only: [] do
|
resources :colors, only: [] do
|
||||||
resources :pet_types, only: [:index]
|
resources :pet_types, only: [:index]
|
||||||
|
|
Loading…
Reference in a new issue