Sha256: ba4790799b6bfb5ac05ec7839824126e18005c34bbfcf18ada76eee78e229503

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module Spree
  module Api
    class StatesController < Spree::Api::BaseController
      skip_before_filter :set_expiry

      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

2 entries across 2 versions & 1 rubygems

Version Path
spree_api-2.1.1 app/controllers/spree/api/states_controller.rb
spree_api-2.1.0 app/controllers/spree/api/states_controller.rb