1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

9 commits

Author SHA1 Message Date
Rafael Mendonça França
93034ad7fe
Reuse the Parameters#to_h check in the routing helpers
Since this protection is now in Parameters we can use it instead of
reimplementing again.
2017-04-18 18:57:13 -04:00
Andrew White
35afd2c53b Add support for calling nested direct routes (#28462)
Not all requirements can be expressed in terms of polymorphic url
options so add a `route_for` method that allows calling another
direct route (or regular named route) which a set of arguments, e.g:

    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, e.g.

    threadable_path(threadable) # => /buckets/1
    threadable_url(threadable)  # => http://example.com/buckets/1
2017-03-17 18:07:09 +01:00
Andrew White
630e709ea6 Clarify use of params in direct
Since a `direct` url helper block is evaluated using `instance_exec`
then methods that are available in the instance context can be
accessed, e.g. the params object in a controller action or view.

This wasn't clear from the example so expand on that point and add
a test case for this situation.
2017-02-22 21:22:22 +00:00
Andrew White
d7c1e62c2c Split direct method into two
Use a separate method called `resolve` for the custom polymorphic
mapping to clarify the API.
2017-02-21 15:30:48 +00:00
Andrew White
3bf47b018b Add custom polymorphic mapping
Allow the use of `direct` to specify custom mappings for polymorphic_url, e.g:

  resource :basket
  direct(class: "Basket") { [:basket] }

This will then generate the following:

  >> link_to "Basket", @basket
  => <a href="/basket">Basket</a>

More importantly it will generate the correct url when used with `form_for`.

Fixes #1769.
2017-02-21 15:30:47 +00:00
Andrew White
d67e252028 Add test for calling a url helper in Mapper#direct 2017-02-21 15:30:47 +00:00
Andrew White
e96da0a7be Only accept symbols and strings for Mapper#direct 2017-02-21 15:30:46 +00:00
Andrew White
47a27e8950 Rename url_helper to direct 2017-02-21 15:30:46 +00:00
Andrew White
ce7d5fb2e6 Add support for defining custom url helpers in routes.rb
Allow the definition of custom url helpers that will be available
automatically wherever standard url helpers are available. The
current solution is to create helper methods in ApplicationHelper
or some other helper module and this isn't a great solution since
the url helper module can be called directly or included in another
class which doesn't include the normal helper modules.

Reference #22512.
2017-02-21 15:30:46 +00:00