New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Redirect] Allows for Class and Symbol Controller name #363
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should use this feature on generators by default ?
So, Instead of redirect_to "/posts"
, we would see redirect_to PostController, :index
:)
That would be a great idea. We should also have the ‘link_to’ jasper helpers user class name |
We need to create url_for and have link_to and redirect_to translate links with that like in rails. |
a87cb04
to
5d96866
Compare
5d96866
to
c3857c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work with a url in which :id or other :params are in the middle of the urls such as posts/1/edit
?
A couple of changes introduced in the last 2 commits. I have decided to simplified the redirect api. There is only 3 possible ways to redirect now:
Why?
|
567e6e0
to
ee61ce1
Compare
src/amber/router/route.cr
Outdated
@@ -49,7 +49,11 @@ module Amber | |||
{result, params} | |||
end | |||
|
|||
def match?(controller, action) | |||
def match?(controller : Class, action : Symbol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is separated into 2 method so we don't have to perform checks or substitutions for /Controller$/
Issue: #353 > As a developer I would like to pass and full controller name to a redirect as a class or symbol and allow for the redirection to happen Example `redirect_to controller: :HomeController, action: :index` - Would be nice to accept HelloController::Index or Admin::UserController:Index
Looking up routes base on controller and action in a radix tree causes On2 many cases because of the radix tree. To avoid that pain this adds hash table to perform lookups by conntroller name and action while this might consume more memory it performs better and makes the code cleaner and lookups based on controller#action are now more reliable Signed-off-by: Elias Perez <eliasjpr@gmail.com>
Since it is now using hash table lookup for redirects there is no need for raising errors, if the controller action combination does not exists it throws KeyError exception. Signed-off-by: Elias Perez <eliasjpr@gmail.com>
Signed-off-by: Elias Perez <eliasjpr@gmail.com>
6cb2fdc
to
451c9c5
Compare
* [REDIRECT] Allows for Class and Symbol Full Controller name Issue: #353 > As a developer I would like to pass and full controller name to a redirect as a class or symbol and allow for the redirection to happen Example `redirect_to controller: :HomeController, action: :index` - Would be nice to accept HelloController::Index or Admin::UserController:Index * fixup! [REDIRECT] Allows for Class and Symbol Full Controller name * Adds Hash Table Lookup for Routes Looking up routes base on controller and action in a radix tree causes On2 many cases because of the radix tree. To avoid that pain this adds hash table to perform lookups by conntroller name and action while this might consume more memory it performs better and makes the code cleaner and lookups based on controller#action are now more reliable Signed-off-by: Elias Perez <eliasjpr@gmail.com> * Removes Redirect Exception Since it is now using hash table lookup for redirects there is no need for raising errors, if the controller action combination does not exists it throws KeyError exception. Signed-off-by: Elias Perez <eliasjpr@gmail.com> * Cleanup and fixes specs Signed-off-by: Elias Perez <eliasjpr@gmail.com> * Cleanup
* [REDIRECT] Allows for Class and Symbol Full Controller name Issue: #353 > As a developer I would like to pass and full controller name to a redirect as a class or symbol and allow for the redirection to happen Example `redirect_to controller: :HomeController, action: :index` - Would be nice to accept HelloController::Index or Admin::UserController:Index * fixup! [REDIRECT] Allows for Class and Symbol Full Controller name * Adds Hash Table Lookup for Routes Looking up routes base on controller and action in a radix tree causes On2 many cases because of the radix tree. To avoid that pain this adds hash table to perform lookups by conntroller name and action while this might consume more memory it performs better and makes the code cleaner and lookups based on controller#action are now more reliable Signed-off-by: Elias Perez <eliasjpr@gmail.com> * Removes Redirect Exception Since it is now using hash table lookup for redirects there is no need for raising errors, if the controller action combination does not exists it throws KeyError exception. Signed-off-by: Elias Perez <eliasjpr@gmail.com> * Cleanup and fixes specs Signed-off-by: Elias Perez <eliasjpr@gmail.com> * Cleanup Former-commit-id: 656c3f6
Issue: #353
Example
redirect_to controller: :HomeController, action: :index
Admin::UserController:Index