Sha256: 2ec0eaf37598493f1a69d0fb9b481f73a3920d7f0a247577fdd709b448d19486

Contents?: true

Size: 860 Bytes

Versions: 17

Compression:

Stored size: 860 Bytes

Contents

module Spree
  module Api
    class StatesController < Spree::Api::BaseController
      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

        respond_with(@states)
      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

17 entries across 17 versions & 1 rubygems

Version Path
solidus_api-2.0.3 app/controllers/spree/api/states_controller.rb
solidus_api-1.4.2 app/controllers/spree/api/states_controller.rb
solidus_api-1.3.2 app/controllers/spree/api/states_controller.rb
solidus_api-2.0.2 app/controllers/spree/api/states_controller.rb
solidus_api-1.4.1 app/controllers/spree/api/states_controller.rb
solidus_api-2.0.1 app/controllers/spree/api/states_controller.rb
solidus_api-2.0.0 app/controllers/spree/api/states_controller.rb
solidus_api-1.4.0 app/controllers/spree/api/states_controller.rb
solidus_api-2.0.0.rc1 app/controllers/spree/api/states_controller.rb
solidus_api-1.4.0.rc1 app/controllers/spree/api/states_controller.rb
solidus_api-2.0.0.beta1 app/controllers/spree/api/states_controller.rb
solidus_api-1.4.0.beta1 app/controllers/spree/api/states_controller.rb
solidus_api-1.3.1 app/controllers/spree/api/states_controller.rb
solidus_api-1.3.0 app/controllers/spree/api/states_controller.rb
solidus_api-1.3.0.rc2 app/controllers/spree/api/states_controller.rb
solidus_api-1.3.0.rc1 app/controllers/spree/api/states_controller.rb
solidus_api-1.3.0.beta1 app/controllers/spree/api/states_controller.rb