PageRenderTime 1123ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

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