Sha256: 3102ce5647d43cb268f0140ad55e60fd8505c8709c8c6b4b40b76f4d158e144b

Contents?: true

Size: 959 Bytes

Versions: 39

Compression:

Stored size: 959 Bytes

Contents

module Spree
  module Api
    module V1
      class StatesController < Spree::Api::BaseController
        skip_before_action :authenticate_user

        def index
          @states = scope.ransack(params[:q]).result.includes(:country)

          if params[:page] || params[:per_page]
            @states = @states.page(params[:page]).per(params[:per_page])
          end

          state = @states.last
          respond_with(@states) if stale?(state)
        end

        def show
          @state = scope.find(params[:id])
          respond_with(@state)
        end

        private

        def scope
          if params[:country_id]
            @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
            @country.states.accessible_by(current_ability, :read).order('name ASC')
          else
            State.accessible_by(current_ability, :read).order('name ASC')
          end
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
spree_api-3.7.14.1 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.14 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.13 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.12 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.11 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.4.6 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.10 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.9 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.8 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.7 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.6 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.5 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.4 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.3 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.2 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.1 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.0 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.0.rc3 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.0.rc2 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.7.0.rc1 app/controllers/spree/api/v1/states_controller.rb