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.8.4 app/controllers/spree/api/states_controller.rb
solidus_api-2.8.3 app/controllers/spree/api/states_controller.rb
solidus_api-2.7.2 app/controllers/spree/api/states_controller.rb
solidus_api-2.6.4 app/controllers/spree/api/states_controller.rb
solidus_api-2.8.2 app/controllers/spree/api/states_controller.rb
solidus_api-2.8.1 app/controllers/spree/api/states_controller.rb
solidus_api-2.6.3 app/controllers/spree/api/states_controller.rb
solidus_api-2.8.0 app/controllers/spree/api/states_controller.rb
solidus_api-2.7.1 app/controllers/spree/api/states_controller.rb
solidus_api-2.6.2 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.14 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.13 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.12 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.11 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.10 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.9 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.8 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.7 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.6 app/controllers/spree/api/states_controller.rb
solidus_api_devise_token_auth-2.8.0.alpha.5 app/controllers/spree/api/states_controller.rb