refund_food.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #encoding
  2. module RailsAdmin
  3. module Config
  4. module Actions
  5. class RefundFood < RailsAdmin::Config::Actions::Base
  6. register_instance_option :visible? do
  7. unless bindings[:object].blank?
  8. authorized? && bindings[:object].status == 1
  9. else
  10. authorized?
  11. end
  12. end
  13. register_instance_option :member do
  14. true
  15. end
  16. register_instance_option :link_icon do
  17. 'icon-plane'
  18. end
  19. register_instance_option :pjax? do
  20. false
  21. end
  22. register_instance_option :controller do
  23. Proc.new do
  24. require 'rest-client'
  25. rd = EmployStaticFood.where("id = ? and status = ? ",@object.id,1).first
  26. n = "退餐成功"
  27. if !rd.blank?
  28. n = "已退餐成功"
  29. url = "#{CONFIG_FILE["xj_host"]}/base/rails-unsubcribe-by-id?id=#{@object.id}"
  30. begin
  31. ret = RestClient.get url, {} #per_page: 5
  32. rescue Exception => e
  33. n = "退餐失败!"
  34. end
  35. end
  36. redirect_to :back, notice: "#{n}"
  37. end
  38. end
  39. end
  40. end
  41. end
  42. end