You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
637B

  1. Rails.application.assets.context_class.class_eval do
  2. def path(name, params=[], **options)
  3. helper = "#{name}_path"
  4. names = []
  5. replace = []
  6. params.each_with_index do |n, p|
  7. arg = "__p#{p}__"
  8. names << arg
  9. replace << [arg, "\#{#{n}}"]
  10. end
  11. query_params = options.delete :params
  12. unless query_params.nil?
  13. query_params.each_with_index do |n, p|
  14. arg = "__q#{p}__"
  15. names << arg
  16. replace << [arg, "\#{#{n}}"]
  17. options[n] = arg
  18. end
  19. end
  20. path = Rails.application.routes.url_helpers.send helper, *names, **options
  21. replace.each { |p, n| path.sub! p, n }
  22. "#{config.relative_url_root}#{path}"
  23. end
  24. end