generate_menu.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # encoding:utf-8
  2. module RailsAdmin
  3. module Config
  4. module Actions
  5. class GenerateMenu < RailsAdmin::Config::Actions::Base
  6. register_instance_option :visible? do
  7. if not bindings[:object].blank?
  8. authorized? && bindings[:object].class == WxMenu && bindings[:object].action == 'root'
  9. else
  10. authorized?
  11. end
  12. end
  13. # We want the action on members, not the Users collection
  14. register_instance_option :member do
  15. true
  16. end
  17. register_instance_option :link_icon do
  18. 'icon-refresh'
  19. end
  20. # You may or may not want pjax for your action
  21. register_instance_option :pjax? do
  22. false
  23. end
  24. register_instance_option :controller do
  25. Proc.new do
  26. require 'rest-client'
  27. root_menu = WxMenu.where("id=?", params[:id]).first
  28. n = "生成菜单成功!"
  29. if not root_menu.blank?
  30. gzh_id = root_menu.wx_gongzhonghao_id
  31. url = "#{CONFIG_FILE["api_host"]}/railsadmin/wx_menu"
  32. begin
  33. ret = RestClient.post url, {gzhId: gzh_id}
  34. rescue Exception => e
  35. p "************ generate menu fail . #{e.to_s}"
  36. n = "生成菜单失败!"
  37. end
  38. end
  39. redirect_to :back, notice: "#{n}"
  40. end
  41. end
  42. end
  43. end
  44. end
  45. end