Sha256: c25d5aca5630592c6b20a32fa3caf93ff79d1b8894d38c090a13b4633158243e

Contents?: true

Size: 1.01 KB

Versions: 40

Compression:

Stored size: 1.01 KB

Contents

module Spree
  module Api
    class StatesController < Spree::Api::BaseController
      skip_before_filter :set_expiry
      skip_before_filter :check_for_user_or_api_key
      skip_before_filter :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 = Country.accessible_by(current_ability, :read).find(params[:country_id])
            return @country.states.accessible_by(current_ability, :read)
          else
            return State.accessible_by(current_ability, :read)
          end
        end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
spree_api-2.3.13 app/controllers/spree/api/states_controller.rb
spree_api-2.2.14 app/controllers/spree/api/states_controller.rb
spree_api-2.3.12 app/controllers/spree/api/states_controller.rb
spree_api-2.2.13 app/controllers/spree/api/states_controller.rb
spree_api-2.3.11 app/controllers/spree/api/states_controller.rb
spree_api-2.2.12 app/controllers/spree/api/states_controller.rb
spree_api-2.3.10 app/controllers/spree/api/states_controller.rb
spree_api-2.3.9 app/controllers/spree/api/states_controller.rb
spree_api-2.2.11 app/controllers/spree/api/states_controller.rb
spree_api-2.2.10 app/controllers/spree/api/states_controller.rb
spree_api-2.3.8 app/controllers/spree/api/states_controller.rb
spree_api-2.3.7 app/controllers/spree/api/states_controller.rb
spree_api-2.2.9 app/controllers/spree/api/states_controller.rb
spree_api-2.1.12 app/controllers/spree/api/states_controller.rb
spree_api-2.3.6 app/controllers/spree/api/states_controller.rb
spree_api-2.2.8 app/controllers/spree/api/states_controller.rb
spree_api-2.1.11 app/controllers/spree/api/states_controller.rb
spree_api-2.3.5 app/controllers/spree/api/states_controller.rb
spree_api-2.2.7 app/controllers/spree/api/states_controller.rb
spree_api-2.1.10 app/controllers/spree/api/states_controller.rb