ruby - How to use namespace in rails without namespace in url -


i have question routes in rails when using namespaces. example code:

namespace :api     # /api/... api::     namespace :v1       devise_for :users, :controllers => {sessions: 'api/v1/users/sessions', :registrations => "api/v1/users/registrations", :password => 'api/v1/users/passwords'}       resources :events         namespace :informations           resources :agendas           resources :attendees           resources :polls           resources :presentatios           resources :speakers           resources :sponsors           resources :votes           resources :vote_options         end       end     end   end 

i check url in console grep agenda, , results in:

/api/v1/events/:event_id/informations/agendas 

how can remove namespace information url without removing namespace routes?

you can use module option add namespace (as in module wrapping) controllers:

resources :events, module: 'v1/api' 

    prefix verb   uri pattern                controller#action     events    /events(.:format)          v1/api/events#index            post   /events(.:format)          v1/api/events#create  new_event    /events/new(.:format)      v1/api/events#new edit_event    /events/:id/edit(.:format) v1/api/events#edit      event    /events/:id(.:format)      v1/api/events#show            patch  /events/:id(.:format)      v1/api/events#update            put    /events/:id(.:format)      v1/api/events#update            delete /events/:id(.:format)      v1/api/events#destroy 

but makes no sense use versioned api controller without versioned urls! unless believe in either using custom request header or custom accept type. both of had diehard rest purist followers scarce due the fact dang difficult test.

http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong-which-is.html


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -