-
Notifications
You must be signed in to change notification settings - Fork 204
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
[Controller] Adds Route Helper Methods to Controller #362
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Amber::Controller::Helpers | ||
module Route | ||
def route_action | ||
context.request_handler.action | ||
end | ||
|
||
def route_resource | ||
context.request_handler.resource | ||
end | ||
|
||
def route_scope | ||
context.request_handler.scope | ||
end | ||
|
||
def route_controller | ||
context.request_handler.controller | ||
end | ||
|
||
def controller_name | ||
self.class.name.gsub(/Controller/i, "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this regex, I would anchor to the end. And does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would people want the controller name downcased? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You guys are correct I will also fix the regex. I looked at the rails implementation https://apidock.com/rails/ActionController/Metal/controller_name/class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use sub instead of gsub since we only want to replace once. |
||
end | ||
end | ||
end |
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 all of these need to be prefixed with
route_
?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.
I prefixed to avoid name collisions with methods define by the user. I am open to suggestions