PageRenderTime 1417ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/api/app/controllers/spree/api/v1/states_controller.rb

https://gitlab.com/adamlwalker/spree
Ruby | 40 lines | 35 code | 5 blank | 0 comment | 4 complexity | 59b7125a60c98547425d7752a270d7b5 MD5 | raw file
  1. module Spree
  2. module Api
  3. module V1
  4. class StatesController < Spree::Api::BaseController
  5. skip_before_action :set_expiry
  6. skip_before_action :check_for_user_or_api_key
  7. skip_before_action :authenticate_user
  8. def index
  9. @states = scope.ransack(params[:q]).result.
  10. includes(:country).order('name ASC')
  11. if params[:page] || params[:per_page]
  12. @states = @states.page(params[:page]).per(params[:per_page])
  13. end
  14. state = @states.last
  15. if stale?(state)
  16. respond_with(@states)
  17. end
  18. end
  19. def show
  20. @state = scope.find(params[:id])
  21. respond_with(@state)
  22. end
  23. private
  24. def scope
  25. if params[:country_id]
  26. @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
  27. return @country.states.accessible_by(current_ability, :read)
  28. else
  29. return State.accessible_by(current_ability, :read)
  30. end
  31. end
  32. end
  33. end
  34. end
  35. end