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

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

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