Guest User

Untitled

a guest
Apr 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. module ActionController
  2. module PolymorphicRoutes
  3. def build_named_route_call(records, namespace, inflection, options = {})
  4. unless records.is_a?(Array)
  5. record = extract_record(records)
  6. route = ''
  7. else
  8. record = records.pop
  9.  
  10. route = records.inject("") do |string, parent|
  11. if parent.is_a?(Symbol) || parent.is_a?(String)
  12. string << "#{parent}_"
  13. else
  14. ## HACK TO NOT CRASH ON POLYMORPHIC ROUTES FOR VENDOR/CLIENT
  15. if (parent.class.superclass == User)
  16. string << "#{RecordIdentifier.__send__("plural_class_name", parent.class.superclass)}".singularize
  17. else
  18. string << "#{RecordIdentifier.__send__("plural_class_name", parent)}".singularize
  19. end
  20. # string << "#{RecordIdentifier.__send__("plural_class_name", parent)}".singularize
  21. ## END HACK
  22. string << "_"
  23. end
  24. end
  25. end
  26.  
  27. if record.is_a?(Symbol) || record.is_a?(String)
  28. route << "#{record}_"
  29. else
  30. route << "#{RecordIdentifier.__send__("plural_class_name", record)}"
  31. route = route.singularize if inflection == :singular
  32. route << "_"
  33. end
  34.  
  35. action_prefix(options) + namespace + route + routing_type(options).to_s
  36. end
  37. end
  38. end
Add Comment
Please, Sign In to add comment