Hi, Just started using rails, and am using edge. I''d like to have an area (url location) of the site that manages the models (products, product options, categories, orders, content etc.). My first thought (products for example) was to create an AdminProductController controller, that would extend the ProductController that was generated by using scaffold_resource script. Then, in the ProductController I would specify with a filter which actions should be protected. Would doing this, "trick" Rails into getting me the correct views and layouts? It seems backwards to me, to put the authorization in the generated ProductController. Is it still RESTful to have a url like: /admin/product/1;edit ??? Or do I switch the view and layout and allowed actions based on the user authentication and go with /product/1;edit - for some reason that bothers me? So... I have the ProductController, a set of public views with a set of actions, a set of admin views and set of actions, and different layouts for each public and admin views. How is this done now with the new REST stuff? Would someone be so kind as to actually post an example? Please? :) I''m confused! Thank you! - matt --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Jan-13 14:25 UTC
Re: Edge, RESTful controllers and an admin section. How?
Yes, Virginia, you can have RESTful controllers inside an admin section. First thing is to make sure you''re creating your controllers correctly. script/generate controller Admin/Products This will generate Admin::ProductsController. I find it easier to have them all descend from a Admin::CommonController which in turn descends from ActiveRecord::Base, that way they can all inherit admin actions from Admin::CommonController instead of having to add them to each admin controller. Note: Admin/Products needs to be plural because you''re going to end up mapping the products resources in routes.rb as plural. At least, that''s the way it''s set up. Next, you''ll need your [admin] routes set up like this: map.with_options :path_prefix => "/admin", :name_prefix => "admin" do |m| m.resources :products, :controller => "admin/products" end Notice you have to tell it to use the "admin/products" controller manually. It would look for "products" controller without it. Also, you need to use the :path_prefix to make the route include the initial "/admin" part of the URI. You don''t have to use the :name_prefix but I find it''s handy because it allows you to reuse the named route "products_url" for another [non-admin] controller. However, it does create named routes like the oddly ordered admin_new_product_url. Your call on which way you prefer that. Hope that helps. RSL On 1/10/07, goodieboy <goodieBoy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, > > Just started using rails, and am using edge. I''d like to have an area > (url location) of the site that manages the models (products, product > options, categories, orders, content etc.). My first thought (products > for example) was to create an AdminProductController controller, that > would extend the ProductController that was generated by using > scaffold_resource script. Then, in the ProductController I would > specify with a filter which actions should be protected. Would doing > this, "trick" Rails into getting me the correct views and layouts? It > seems backwards to me, to put the authorization in the generated > ProductController. > > Is it still RESTful to have a url like: /admin/product/1;edit ??? > > Or do I switch the view and layout and allowed actions based on the > user authentication and go with /product/1;edit - for some reason that > bothers me? > > So... I have the ProductController, a set of public views with a set of > actions, a set of admin views and set of actions, and different layouts > for each public and admin views. How is this done now with the new REST > stuff? Would someone be so kind as to actually post an example? Please? > :) I''m confused! > > Thank you! > > - matt > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Ahh, I didn''t see this post until now! Thank you very much. I was almost in tears. Where can I find more information on the map object? I don''t know what map.with_options does? - matt On Jan 13, 9:25 am, "Russell Norris" <sco...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, Virginia, you can have RESTful controllers inside an admin section. > First thing is to make sure you''re creating your controllers correctly. > > script/generate controller Admin/Products > > This will generate Admin::ProductsController. I find it easier to have them > all descend from a Admin::CommonController which in turn descends from > ActiveRecord::Base, that way they can all inherit admin actions from > Admin::CommonController instead of having to add them to each admin > controller. Note: Admin/Products needs to be plural because you''re going to > end up mapping the products resources in routes.rb as plural. At least, > that''s the way it''s set up. > > Next, you''ll need your [admin] routes set up like this: > > map.with_options :path_prefix => "/admin", :name_prefix => "admin" do |m| > m.resources :products, :controller => "admin/products" > end > > Notice you have to tell it to use the "admin/products" controller manually. > It would look for "products" controller without it. Also, you need to use > the :path_prefix to make the route include the initial "/admin" part of the > URI. You don''t have to use the :name_prefix but I find it''s handy because it > allows you to reuse the named route "products_url" for another [non-admin] > controller. However, it does create named routes like the oddly ordered > admin_new_product_url. Your call on which way you prefer that. > > Hope that helps. > > RSL > > On 1/10/07, goodieboy <goodie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > Just started using rails, and am using edge. I''d like to have an area > > (url location) of the site that manages the models (products, product > > options, categories, orders, content etc.). My first thought (products > > for example) was to create an AdminProductController controller, that > > would extend the ProductController that was generated by using > > scaffold_resource script. Then, in the ProductController I would > > specify with a filter which actions should be protected. Would doing > > this, "trick" Rails into getting me the correct views and layouts? It > > seems backwards to me, to put the authorization in the generated > > ProductController. > > > Is it still RESTful to have a url like: /admin/product/1;edit ??? > > > Or do I switch the view and layout and allowed actions based on the > > user authentication and go with /product/1;edit - for some reason that > > bothers me? > > > So... I have the ProductController, a set of public views with a set of > > actions, a set of admin views and set of actions, and different layouts > > for each public and admin views. How is this done now with the new REST > > stuff? Would someone be so kind as to actually post an example? Please? > > :) I''m confused! > > > Thank you! > > > - matt--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Jan-19 16:28 UTC
Re: Edge, RESTful controllers and an admin section. How?
To be honest, I don''t remember where I found the documentation about map.with_options. I know there''s a blog post somewhere out there that I learned more about it but I first found it when I was going through the source code for Mephisto. If you combine the info in the REST-y Rails cheatsheet [http://nubyonrails.com/articles/2006/10/09/peepcode-rest-basics] and this post, [http://www.pinupgeek.com/2006/5/24/rails-routing-demystified] you should be able to interpolate the rest. Hope that helps. RSL On 1/18/07, goodieboy <goodieBoy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Ahh, I didn''t see this post until now! Thank you very much. I was > almost in tears. Where can I find more information on the map object? I > don''t know what map.with_options does? > > - matt > > On Jan 13, 9:25 am, "Russell Norris" <sco...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Yes, Virginia, you can have RESTful controllers inside an admin section. > > First thing is to make sure you''re creating your controllers correctly. > > > > script/generate controller Admin/Products > > > > This will generate Admin::ProductsController. I find it easier to have > them > > all descend from a Admin::CommonController which in turn descends from > > ActiveRecord::Base, that way they can all inherit admin actions from > > Admin::CommonController instead of having to add them to each admin > > controller. Note: Admin/Products needs to be plural because you''re going > to > > end up mapping the products resources in routes.rb as plural. At least, > > that''s the way it''s set up. > > > > Next, you''ll need your [admin] routes set up like this: > > > > map.with_options :path_prefix => "/admin", :name_prefix => "admin" do > |m| > > m.resources :products, :controller => "admin/products" > > end > > > > Notice you have to tell it to use the "admin/products" controller > manually. > > It would look for "products" controller without it. Also, you need to > use > > the :path_prefix to make the route include the initial "/admin" part of > the > > URI. You don''t have to use the :name_prefix but I find it''s handy > because it > > allows you to reuse the named route "products_url" for another > [non-admin] > > controller. However, it does create named routes like the oddly ordered > > admin_new_product_url. Your call on which way you prefer that. > > > > Hope that helps. > > > > RSL > > > > On 1/10/07, goodieboy <goodie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Hi, > > > > > Just started using rails, and am using edge. I''d like to have an area > > > (url location) of the site that manages the models (products, product > > > options, categories, orders, content etc.). My first thought (products > > > for example) was to create an AdminProductController controller, that > > > would extend the ProductController that was generated by using > > > scaffold_resource script. Then, in the ProductController I would > > > specify with a filter which actions should be protected. Would doing > > > this, "trick" Rails into getting me the correct views and layouts? It > > > seems backwards to me, to put the authorization in the generated > > > ProductController. > > > > > Is it still RESTful to have a url like: /admin/product/1;edit ??? > > > > > Or do I switch the view and layout and allowed actions based on the > > > user authentication and go with /product/1;edit - for some reason that > > > bothers me? > > > > > So... I have the ProductController, a set of public views with a set > of > > > actions, a set of admin views and set of actions, and different > layouts > > > for each public and admin views. How is this done now with the new > REST > > > stuff? Would someone be so kind as to actually post an example? > Please? > > > :) I''m confused! > > > > > Thank you! > > > > > - matt > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
I was like looking for something similar aswell thanks for the tip. You can also found out about map.with_options here http://api.rubyonrails.com/classes/ActionController/Routing.html cheers. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---