aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-12-12 14:56:21 +0900
committerGitHub <noreply@github.com>2017-12-12 14:56:21 +0900
commitc5462d1f27f7d43624e188008b0062d1d25369aa (patch)
tree2f7c2541fb84451c8045add48b1d73a9bb072142 /guides
parent6129d1f937c64eadd6118a89fea556b201b6b4d4 (diff)
parent3dc774f37196634c0ead612fae52b37aa8a5838c (diff)
downloadrails-c5462d1f27f7d43624e188008b0062d1d25369aa.tar.gz
rails-c5462d1f27f7d43624e188008b0062d1d25369aa.tar.bz2
rails-c5462d1f27f7d43624e188008b0062d1d25369aa.zip
Merge pull request #31402 from yhirano55/update_routing_guide_for_direct_method
[ci skip] Update routing guide for Direct & resolved routes
Diffstat (limited to 'guides')
-rw-r--r--guides/source/routing.md43
1 files changed, 43 insertions, 0 deletions
diff --git a/guides/source/routing.md b/guides/source/routing.md
index 638f77be13..efc0e32b56 100644
--- a/guides/source/routing.md
+++ b/guides/source/routing.md
@@ -852,6 +852,49 @@ You can specify unicode character routes directly. For example:
get 'こんにちは', to: 'welcome#index'
```
+### Direct routes
+
+You can create custom URL helpers directly. For example:
+
+```ruby
+direct :homepage do
+ "http://www.rubyonrails.org"
+end
+
+# >> homepage_url
+# => "http://www.rubyonrails.org"
+```
+
+The return value of the block must be a valid argument for the `url_for` method. So, you can pass a valid string URL, Hash, Array, an Active Model instance, or an Active Model class.
+
+```ruby
+direct :commentable do |model|
+ [ model, anchor: model.dom_id ]
+end
+
+direct :main do
+ { controller: 'pages', action: 'index', subdomain: 'www' }
+end
+```
+
+### Using `resolve`
+
+The `resolve` method allows customizing polymorphic mapping of models. For example:
+
+``` ruby
+resource :basket
+
+resolve("Basket") { [:basket] }
+```
+
+``` erb
+<%= form_for @basket do |form| %>
+ <!-- basket form -->
+<% end %>
+```
+
+This will generate the singular URL `/basket` instead of the usual `/baskets/:id`.
+
Customizing Resourceful Routes
------------------------------