Sha256: ca34bb20acae9db7433cf6c23514ece894618237ef33e71e1eb7823341b2acb4

Contents?: true

Size: 858 Bytes

Versions: 50

Compression:

Stored size: 858 Bytes

Contents

# frozen_string_literal: true

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 = paginate(@states)
        end

        respond_with(@states)
      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])
          @country.states.accessible_by(current_ability, :read)
        else
          Spree::State.accessible_by(current_ability, :read)
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
solidus_api-2.10.5 app/controllers/spree/api/states_controller.rb
solidus_api-2.10.3 app/controllers/spree/api/states_controller.rb
solidus_api-2.10.2 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.6 app/controllers/spree/api/states_controller.rb
solidus_api-2.8.6 app/controllers/spree/api/states_controller.rb
solidus_api-2.10.1 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.5 app/controllers/spree/api/states_controller.rb
solidus_api-2.10.0 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.4 app/controllers/spree/api/states_controller.rb
solidus_api-2.6.6 app/controllers/spree/api/states_controller.rb
solidus_api-2.7.4 app/controllers/spree/api/states_controller.rb
solidus_api-2.8.5 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.3 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.2 app/controllers/spree/api/states_controller.rb
solidus_api-2.10.0.beta1 app/controllers/spree/api/states_controller.rb
solidus_api-2.7.3 app/controllers/spree/api/states_controller.rb
solidus_api-2.6.5 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.1 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.0 app/controllers/spree/api/states_controller.rb
solidus_api-2.9.0.rc.1 app/controllers/spree/api/states_controller.rb