aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing/custom_url_helpers_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add support for calling nested direct routes (#28462)Andrew White2017-03-171-8/+28
| | | | | | | | | | | | | | | | | | | | 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
* Clarify use of params in `direct`Andrew White2017-02-221-0/+14
| | | | | | | | | 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.
* Split direct method into twoAndrew White2017-02-211-0/+291
| | | | | Use a separate method called `resolve` for the custom polymorphic mapping to clarify the API.
* Add custom polymorphic mappingAndrew White2017-02-211-145/+0
| | | | | | | | | | | | | | | | 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.
* Add test for calling a url helper in Mapper#directAndrew White2017-02-211-0/+7
|
* Only accept symbols and strings for Mapper#directAndrew White2017-02-211-0/+17
|
* Rename url_helper to directAndrew White2017-02-211-12/+12
|
* Add support for defining custom url helpers in routes.rbAndrew White2017-02-211-0/+121
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.