Module: Gen::UrlHelpers
- Defined in:
- docs/api/stubs/generated_app.rb
Overview
The *_path and *_url helpers spin run gen writes into
gen/routes.rb, one pair per named route in config/routes.rb. They are
included into every controller and resolved by name in templates. These
are the ones examples/blog’s routes generate:
Cybertrain::Routes.draw do
root "articles#index"
resources :articles do |articles|
articles.resources :comments, only: [:create, :destroy]
end
end
Arguments are positional, one per :param in the path: a record (its
to_param, the id), an Integer or a String,
percent-encoded as one segment. nil raises ArgumentError "missing route
parameter". *_url prepends Cybertrain.url_root.
Keywords after them land in the trailing options Hash (spec 2.6):
format: adds an extension, anchor: a fragment, and every other key
becomes a query parameter, in the order given, escaped. A nil value
leaves its key out, an Array gives key[]=v per element, a Hash raises
ArgumentError. The same keywords work on a path helper in a template.
article_path(@article, page: 2) # => "/articles/3?page=2"
article_path(@article, format: :json) # => "/articles/3.json"
articles_path(q: "a b", tag: ["x", "y"]) # => "/articles?q=a+b&tag%5B%5D=x&tag%5B%5D=y"
article_path(@article, page: 2, anchor: "c") # => "/articles/3?page=2#c"
See Cybertrain::Routes.draw for the names each route gets.
Instance Method Summary collapse
-
#article_comment_path(article, comment, options = {}) ⇒ String
The nested member.
-
#article_comments_path(article, options = {}) ⇒ String
The nested collection: one argument per level.
-
#article_path(article, options = {}) ⇒ String
"/articles/1". -
#articles_path(options = {}) ⇒ String
"/articles". -
#articles_url(options = {}) ⇒ String
Cybertrain.url_root +
"/articles". -
#edit_article_path(article, options = {}) ⇒ String
"/articles/1/edit". -
#new_article_path(options = {}) ⇒ String
"/articles/new". -
#root_path(options = {}) ⇒ String
"/".
Instance Method Details
#article_comment_path(article, comment, options = {}) ⇒ String
The nested member.
1293 |
# File 'docs/api/stubs/generated_app.rb', line 1293 def article_comment_path(article, comment, = {}); end |
#article_comments_path(article, options = {}) ⇒ String
The nested collection: one argument per level.
1285 |
# File 'docs/api/stubs/generated_app.rb', line 1285 def article_comments_path(article, = {}); end |
#article_path(article, options = {}) ⇒ String
Returns "/articles/1".
1272 |
# File 'docs/api/stubs/generated_app.rb', line 1272 def article_path(article, = {}); end |
#articles_path(options = {}) ⇒ String
Returns "/articles".
1253 |
# File 'docs/api/stubs/generated_app.rb', line 1253 def articles_path( = {}) = Cybertrain::Gen.("/articles", ) |
#articles_url(options = {}) ⇒ String
Returns Cybertrain.url_root + "/articles".
1258 |
# File 'docs/api/stubs/generated_app.rb', line 1258 def articles_url( = {}) = Cybertrain.url_root + articles_path() |
#edit_article_path(article, options = {}) ⇒ String
Returns "/articles/1/edit".
1278 |
# File 'docs/api/stubs/generated_app.rb', line 1278 def edit_article_path(article, = {}); end |
#new_article_path(options = {}) ⇒ String
Returns "/articles/new".
1263 |
# File 'docs/api/stubs/generated_app.rb', line 1263 def new_article_path( = {}) = Cybertrain::Gen.("/articles/new", ) |
#root_path(options = {}) ⇒ String
Returns "/".
1248 |
# File 'docs/api/stubs/generated_app.rb', line 1248 def root_path( = {}) = Cybertrain::Gen.("/", ) |