Namespace is semantically different in that sub resources are nestled under
an instance of the resource they represent, not just a static string.

i.e., /resource/1/subresource, not /resource/subresource

On Thu, Jan 18, 2018 at 10:15 AM Rob Biedenharn <rob.biedenh...@gmail.com>
wrote:

> If you don't want the `resources` anyway, why not just use `namespace`:
>
> ==> config/routes.rb <==
> Rails.application.routes.draw do
>   namespace 'users' do
>     get  'unsubscribe'
>     get  ':id/foo', action: :foo, as: :foo
>     post ':id/bar', action: :bar, as: :bar
>   end
> end
>            Prefix Verb URI Pattern                  Controller#Action
> users_unsubscribe GET  /users/unsubscribe(.:format) users#unsubscribe
>         users_foo GET  /users/:id/foo(.:format)     users#foo
>         users_bar POST /users/:id/bar(.:format)     users#bar
>
> -Rob
>
> On 2018-Jan-18, at 08:26 , Kevin Deisz <kevin.de...@gmail.com> wrote:
>
> You can achieve this functionality by throwing this into the top of your
> routes drawing block:
>
> ```
> def subresources(name, &block)
>     resources(name, only: [], &block)
>   end
> ```
>
> since that block is getting instance_eval'd anyway, this will just put
> that method onto the routes object. Then you can:
>
> ```
> subresources :users do
>   ...
> end
> ```
>
> and it'll have the same effect.
>
>
> On Thu, Jan 18, 2018 at 7:57 AM, Nicholas Schwaderer <
> nicholas.schwade...@gmail.com> wrote:
>
>> I feel that `only: []` definitely is not an intuitive approach that shows
>> what you would be trying to achieve in that instance.
>>
>> Also, I believe your only current alternative would be writing out your
>> resourcing 'longhand' outside of an actual resources block in your
>> `routes.rb`, correct? (I have seen all too many apps bloat with a lot of
>> handscrawled routes)
>>
>> But since this is a bit aways from normal `resources` namespace usage
>> maybe your alias ought to go all the way up to `resources` itself.... such
>> as:
>>
>> ```
>> resources_without_crud :users do
>>   ...
>> end
>> ```
>>
>> When I think of `resources` I think of the crud rails magic, and maybe it
>> would help to make that even more explicit. Very interesting thought and
>> thank you for raising it.
>>
>>
>>
>> On Wednesday, January 17, 2018 at 11:43:41 PM UTC, François Belle wrote:
>>>
>>> I would like to propose a feature that would be kind of an alias for
>>>
>>> resources :users, only: [] do
>>>   ...
>>> end
>>>
>>> I thinks it's weird to have to specify an empty array when we need a
>>> resourceful route without the default CRUD generated along.
>>>
>>> It would allow us to use it like the shallow feature
>>> <https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#L1372>
>>> :
>>>
>>> resources :users, without_crud: true do
>>>   get :unsubscribe, on: :collection
>>>   get :foo
>>>   post :bar
>>> end
>>>
>>> And generate only:
>>>
>>> GET /users/unsubscribe
>>> GET /users/:id/foo
>>> POST /users/:id/bar
>>>
>>>
>>> Any feedback would be greatly appreciated, thank you guys!
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to rubyonrails-core+unsubscr...@googlegroups.com.
>> To post to this group, send email to rubyonrails-core@googlegroups.com.
>> Visit this group at https://groups.google.com/group/rubyonrails-core.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Kevin D. Deisz*
> CTO, CultureHQ <https://www.culturehq.com/>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
*Kevin D. Deisz*
CTO, CultureHQ <https://www.culturehq.com>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to