Sha256: 279dfc14c32c7e6a7903876f1165c089f8add9772ab856753b3a21aaa71377e3

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

Contents

module Spree
  module Api
    class StatesController < Spree::Api::BaseController
      skip_before_action :set_expiry
      skip_before_action :check_for_user_or_api_key
      skip_before_action :authenticate_user

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

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

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

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

      private
        def scope
          if params[:country_id]
            @country = Spree::Country.accessible_by(current_ability, :read).find(params[:country_id])
            return @country.states.accessible_by(current_ability, :read)
          else
            return Spree::State.accessible_by(current_ability, :read)
          end
        end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_api-3.0.10 app/controllers/spree/api/states_controller.rb
spree_api-3.0.9 app/controllers/spree/api/states_controller.rb
spree_api-3.0.8 app/controllers/spree/api/states_controller.rb
spree_api-3.0.7 app/controllers/spree/api/states_controller.rb
spree_api-3.0.6.1 app/controllers/spree/api/states_controller.rb
spree_api-3.0.6 app/controllers/spree/api/states_controller.rb
spree_api-3.0.5 app/controllers/spree/api/states_controller.rb
spree_api-3.0.4 app/controllers/spree/api/states_controller.rb
spree_api-2.4.10 app/controllers/spree/api/states_controller.rb
spree_api-3.0.3 app/controllers/spree/api/states_controller.rb
spree_api-2.4.9 app/controllers/spree/api/states_controller.rb
spree_api-3.0.2 app/controllers/spree/api/states_controller.rb
spree_api-2.4.8 app/controllers/spree/api/states_controller.rb
spree_api-3.0.1 app/controllers/spree/api/states_controller.rb
spree_api-2.4.7 app/controllers/spree/api/states_controller.rb