Method: Flame::Dispatcher#path_to
- Defined in:
- lib/flame/dispatcher.rb
#path_to(ctrl, action = :index, args = {}) ⇒ String
Build a path to the given controller and action, with any expected params
97 98 99 100 101 102 103 104 105 |
# File 'lib/flame/dispatcher.rb', line 97 def path_to(ctrl, action = :index, args = {}) route = @app.class.router.find_route(controller: ctrl, action: action) raise Errors::RouteNotFoundError.new(ctrl, action) unless route query = Rack::Utils.build_nested_query args.delete(:params) query = nil if query&.empty? path = route.path.assign_arguments(args) path = '/' if path.empty? URI::Generic.build(path: path, query: query).to_s end |