Hi there, I''m stuck with some very simple routing requirements. Somehow I believe this is not even possible with the new Rails 3 Router: So i have my Admin::SettingsController class in controllers/admin My intention is to access the admin-controllers via /admin/:controller/:action in my routes.rb I add: namespace :admin do match '':controller(/:action(/:id))'' end (I want the admin part of my application to be unRESTful) However, now EVERY controller is accessable via /admin/controller/action!... For example, url_for :controller => ''books'', :action => ''show'' generates "/admin/books/show" ... likewise, url_for :controller => ''admin/settings'', :action => ''group'' now generates "/admin/admin/settings/group" (should be: "/admin/settings/group". How can I get SIMPLE namespace''d controllers to work in rails without affecting other controllers? Does anyone know? Thank you :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Mar 17, 2010 at 3:14 PM, Stefan Buhr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi there, > > I''m stuck with some very simple routing requirements. Somehow I believe > this is not even possible with the new Rails 3 Router: > > So i have my Admin::SettingsController class in controllers/admin > > My intention is to access the admin-controllers via > /admin/:controller/:action > > in my routes.rb I add: > namespace :admin do > match '':controller(/:action(/:id))'' > end (I want the admin part of my application to be unRESTful) > > However, now EVERY controller is accessable via > /admin/controller/action!... For example, url_for :controller => > ''books'', :action => ''show'' generates "/admin/books/show" ... likewise, > url_for :controller => ''admin/settings'', :action => ''group'' now > generates "/admin/admin/settings/group" (should be: > "/admin/settings/group". > > How can I get SIMPLE namespace''d controllers to work in rails without > affecting other controllers? Does anyone know? > > Thank you :) >Stefan, in Rails 3, you can do the following in your routes.rb: namespace :admin do resources :settings end Then, you''ll end up with the following controllers: /admin/settings Good luck, -Conrad> -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Conrad Taylor wrote:> > namespace :admin do resources :settings end > > Then, you''ll end up with the following controllers: > > /admin/settingsHey, thanks for the hint, but resources() only adds the standard actions to the route (index, show, edit, new, create, update, delete). I''m looking for a more generic approach using default routes for many controllers and actions in one namespace. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Mar 17, 2010 at 4:34 PM, Stefan Buhr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Conrad Taylor wrote: > > > > namespace :admin do resources :settings end > > > > Then, you''ll end up with the following controllers: > > > > /admin/settings > > Hey, > > thanks for the hint, but resources() only adds the standard actions to > the route (index, show, edit, new, create, update, delete). I''m looking > for a more generic approach using default routes for many controllers > and actions in one namespace. >Yes, this is correct unless you had another question because it wasn''t clear from the original e-mail. If you would like to add non-standard action(s) to a controller, then you''ll need to do the following: namespace :admin do resources :settings do get :some_action, :on => :member # member route get :some_other_action, :on => :collection # collection route end end Good luck, -Conrad> -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Mar 17, 2010 at 4:34 PM, Stefan Buhr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Conrad Taylor wrote: > > > > namespace :admin do resources :settings end > > > > Then, you''ll end up with the following controllers: > > > > /admin/settings > > Hey, > > thanks for the hint, but resources() only adds the standard actions to > the route (index, show, edit, new, create, update, delete). I''m looking > for a more generic approach using default routes for many controllers > and actions in one namespace. >Stefan, I would also recommend reading following documentation for something that meets your requirements: http://guides.rails.info/routing.html Good luck, -Conrad --> Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Conrad Taylor wrote:> namespace :admin do resources :settings do > get :some_action, :on => :member # member route > get :some_other_action, :on => :collection # collection route > end endYes, someone *could* explicitly define all actions in the routes.rb, but that is exactly what I do not want to do -- this is not even close to a generic solution :P In addition, I dont like the idea of squeezing all the unRESTful parts of the application into resources, when I do not even need or want all the additional RESTful routes. So, the question still stands: Is there a way to have regular (generic!) routes in namespaces like in rails 2? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Conrad Taylor
2010-Mar-18 04:19 UTC
Re: Re: Re: Rails 3 Routing: Namespace''d Controllers?
Sent from my iPhone On Mar 17, 2010, at 5:43 PM, Stefan Buhr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Conrad Taylor wrote: >> namespace :admin do resources :settings do >> get :some_action, :on => :member # member route >> get :some_other_action, :on => :collection # collection route >> end end > > Yes, someone *could* explicitly define all actions in the routes.rb, > but > that is exactly what I do not want to do -- this is not even close > to a > generic solution :PYes, this is true but you have a much greater level of control over your actions. The default routes will make every action in Rails 3.0 use a GET request. Thus, you''ll need to refactor all your views as appropriately.> > In addition, I dont like the idea of squeezing all the unRESTful parts > of the application into resources, when I do not even need or want all > the additional RESTful routes. > > So, the question still stands: Is there a way to have regular > (generic!) > routes in namespaces like in rails 2Please post the Rails 2.x route that you would like to convert to Rails 3.0? -Conrad> -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Conrad Taylor wrote:> Sent from my iPhone > > > Please post the Rails 2.x route that you would like to convert to > Rails 3.0? >Hey Conrad, I think I made a mistake. I was under the impression that following code in rails 2 map.namespace :admin do |admin| admin.connect '':controller/:action/:id'' end was enabling /admin/any_controller/any_action => Addmin::AnyController#any_action but it did not. instead, the default root was still enabled. The above code never worked. Ultimatly, what I am trying to do, is to use the default root but ONLY for controllers in a specific namespace (other parts of the application are using resources) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Stefan Buhr wrote in post #897683:> Conrad Taylor wrote: >> Sent from my iPhone >> >> >> Please post the Rails 2.x route that you would like to convert to >> Rails 3.0? >> > > Hey Conrad, > > I think I made a mistake. > > I was under the impression that following code in rails 2 > map.namespace :admin do |admin| > admin.connect '':controller/:action/:id'' > end > was enabling /admin/any_controller/any_action => > Addmin::AnyController#any_action > but it did not. > > instead, the default root was still enabled. The above code never > worked. > > Ultimatly, what I am trying to do, is to use the default root but ONLY > for controllers in a specific namespace (other parts of the application > are using resources)What your looking for is scope in routes: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing scope "/admin" do match ":controller(/:action(/:id))" resources :posts # :controller => PostsController end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I feel that the following do work. match '':controller(/:action(/:id))'' , :controller=> /admin\/[^\/]+/ In rails3, such a constraint condition for namespaced controllers may be necessary. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.