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

https://github.com/joshnuss/spree-1 · Ruby · 36 lines · 31 code · 5 blank · 0 comment · 4 complexity · 5237655f67ed18bc2de0241d52415c82 MD5 · raw file

  1. module Spree
  2. module Api
  3. class StatesController < Spree::Api::BaseController
  4. skip_before_filter :set_expiry
  5. def index
  6. @states = scope.ransack(params[:q]).result.
  7. includes(:country).order('name ASC')
  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)
  25. else
  26. return State.accessible_by(current_ability, :read)
  27. end
  28. end
  29. end
  30. end
  31. end