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

14 commits

Author SHA1 Message Date
Kir Shatrov
dfcc766163 Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Matthew Draper
3420a14590 Merge pull request #29540 from kirs/rubocop-frozen-string
Enforce frozen string in Rubocop
2017-07-02 01:11:50 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Wilson Bilkovich
250bc33233 Properly register "custom" URL helpers as named helpers.
CustomUrlHelpers were introduced in ce7d5fb2e6, closing issue #22512.
They currently register themselves in an ivar that is never accessed.
This change removes the @custom_helpers special-case, and registers them
the way named routes are normally handled.

Without this, you can get route_defined?(:example_url) == false, while
still being able to call url_helpers.example_url and example_path.

Various popular gems such as 'rspec-rails' make use of route_defined?()
when determining how to proxy method calls or whether to define a route.
2017-06-30 15:53:32 -07:00
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