instance method route_for

Ruby on Rails 8.0.4

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

route_for(name, *args)

Allows calling direct or regular named route.

resources :buckets

direct :recordable do |recording|
  route_for(:bucket, recording.bucket)
end

direct :threadable do |threadable|
  route_for(:recordable, threadable.parent)
end

This maintains the context of the original caller on whether to return a path or full URL, e.g:

threadable_path(threadable)  # => "/buckets/1"
threadable_url(threadable)   # => "http://example.com/buckets/1"

Parameters

name req
args rest
Source
# File actionpack/lib/action_dispatch/routing/url_for.rb, line 222
      def route_for(name, *args)
        public_send(:"#{name}_url", *args)
      end

Defined in actionpack/lib/action_dispatch/routing/url_for.rb line 222 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionDispatch::Routing::UrlFor

Type at least 2 characters to search.

↑↓ navigate · open · esc close