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
Allow setting a symbol as path in scope on routes #8114
Conversation
I think it's fine to support symbols in this case, at least I can't see anything that should block it. A changelog entry would be nice :). Thanks! |
@@ -641,7 +641,7 @@ def scope(*args) | |||
options = args.extract_options! | |||
options = options.dup | |||
|
|||
options[:path] = args.first if args.first.is_a?(String) | |||
options[:path] = args.first.to_s if args.first.is_a?(String) || args.first.is_a?(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.
I think we can just do:
options[:path] = args.first.to_s if args.any?
I don't see any situation where it's going cause a problem. In fact I'm wondering whether we should just use args.flatten.join('/') if args.any?
that way you can do the following:
scope :api, :v1 do
resources :products
end
wdyt?
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 think it's fine to add that support 👍. Not sure @tenderlove has anything to say about it.
I'm not sure I agree with this change. To me, the namespace code is namespacing a url within a string literal, and never a parameter. For example
namepaces things under /api Scoping, on the other hand, can work with parameters and string literals, so when provided with a symbol, it's not completely obvious if it would be transformed to its equivalent string representation or if it would represent a parameter. For example:
and
would do completely different things with this patch, which might confuse people. |
@luke-gru so do you think it should represent a parameter scope, e.g:
|
@pixeltrix I agree that those are the three choices, and 1. is probably not a good one. After giving it a little thought, maybe calling |
@pixeltrix agree with @luke-gru, looks like |
@guilleiguaran can you update to pull request to use |
@pixeltrix done 😄 |
|
||
*Guillermo Iguaran* | ||
|
||
|
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.
✂️
Was surprising found that this example doesn't work: scope :api do resources :users end and the right form to use it is: scope 'api' do resources :users end I think this should work similary as `namespace` where both are allowed. These two are equivalent: namespace :api do resources :users end namespace 'api' do resources :user end
Allow setting a symbol as path in scope on routes
Was surprising found that this example doesn't work:
and the right form to use it is:
I think this should work similary as
namespace
where both are allowed.These two are equivalent: