Sha256: aa1cb9ede38d1b167df9182e590ceff017de7e3b41a3a31fc9bcb67989413087

Contents?: true

Size: 844 Bytes

Versions: 84

Compression:

Stored size: 844 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, :show).find(params[:country_id])
          @country.states.accessible_by(current_ability)
        else
          Spree::State.accessible_by(current_ability)
        end
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-4.4.1 app/controllers/spree/api/states_controller.rb
solidus_api-4.4.0 app/controllers/spree/api/states_controller.rb
solidus_api-4.3.4 app/controllers/spree/api/states_controller.rb
solidus_api-4.2.4 app/controllers/spree/api/states_controller.rb
solidus_api-4.1.5 app/controllers/spree/api/states_controller.rb
solidus_api-4.3.3 app/controllers/spree/api/states_controller.rb
solidus_api-4.3.2 app/controllers/spree/api/states_controller.rb
solidus_api-4.1.4 app/controllers/spree/api/states_controller.rb
solidus_api-4.3.1 app/controllers/spree/api/states_controller.rb
solidus_api-4.3.0 app/controllers/spree/api/states_controller.rb
solidus_api-4.2.3 app/controllers/spree/api/states_controller.rb
solidus_api-4.1.3 app/controllers/spree/api/states_controller.rb
solidus_api-4.0.4 app/controllers/spree/api/states_controller.rb
solidus_api-3.4.6 app/controllers/spree/api/states_controller.rb
solidus_api-4.0.3 app/controllers/spree/api/states_controller.rb
solidus_api-4.1.2 app/controllers/spree/api/states_controller.rb
solidus_api-4.2.2 app/controllers/spree/api/states_controller.rb
solidus_api-3.4.5 app/controllers/spree/api/states_controller.rb
solidus_api-4.2.1 app/controllers/spree/api/states_controller.rb
solidus_api-4.2.0 app/controllers/spree/api/states_controller.rb