I want to make a simple website with rails, but I''m confused about how to setup my controllers. Here''s what I want: 5 pages: Home, Products & Services, Press Center, White Papers & About us So, I''m confused about how to set this up. Should each page have it''s own controller, e.g.: home_controller, products_controller, press_controller, white_papers_controller and about_us_controller Is this a wise design decision? I would like to use a layout "template" for all the pages. How then, if I''m using independent controllers for each page do I share a layout? All the rails site examples I''ve found are kinda non-standard sites with only 1 real page, like a shopping cart, so I''m not sure how to structure my rails app for a site with many pages. Can you cite any examples? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi eggie5, you could read this book "Apress - Beginning Ruby On Rails E-Commerce - From Novice To Professional",there are examples just you mentioned bellow ----- Original Message ---- From: eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: Ruby on Rails: Talk <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Thursday, September 13, 2007 11:37:59 AM Subject: [Rails] Simple rails website design question I want to make a simple website with rails, but I''m confused about how to setup my controllers. Here''s what I want: 5 pages: Home, Products & Services, Press Center, White Papers & About us So, I''m confused about how to set this up. Should each page have it''s own controller, e.g.: home_controller, products_controller, press_controller, white_papers_controller and about_us_controller Is this a wise design decision? I would like to use a layout "template" for all the pages. How then, if I''m using independent controllers for each page do I share a layout? All the rails site examples I''ve found are kinda non-standard sites with only 1 real page, like a shopping cart, so I''m not sure how to structure my rails app for a site with many pages. Can you cite any examples? ____________________________________________________________________________________ Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If your site is just HTML, then stick with one controller. or else split them like this base_controller => [home, press, about us] product_controller => [products] -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Well, all of the pages are pretty much standard, read an object from the database then databind the page. SO that would fit into your one controller idea with many actions for each page. I would like my urls to look like this: www.domain_name.com/products www.domain_name.com/whitepapers www.domain_name.com/about etc... Without any modifications to my routes.rb file the only way to access my pages is to refrene the controller in the path like: www.domain_name.com/base/products How do I set up my urls to work like my list above? On Sep 13, 12:13 am, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> If your site is just HTML, > > then stick with one controller. > > or else split them like this > > base_controller => [home, press, about us] > product_controller => [products] > > -- > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---
On 9/13/07, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I want to make a simple website with rails, but I''m confused about how > to setup my controllers. Here''s what I want: > > 5 pages: Home, Products & Services, Press Center, White Papers & About > us > > So, I''m confused about how to set this up. Should each page have it''s > own controller, e.g.: > > home_controller, products_controller, press_controller, > white_papers_controller and about_us_controller > > Is this a wise design decision?Can''t tell, with the information given. The very "general" rule is to have a controller per model, so that''s a good place to start. But it''s not necessary to agonize over the structure of your controllers. Rather than trying to envision how the whole thing will look like when it''s done, just implement a very small part of it. Start with one controller. Then when you need to add stuff, you have a choice: do I add an action to my current controller or do I create a new controller? Well, make your best guess and see how that goes. If it turns out to be problematic for whatever reason, it''s easy to back up and take the other direction. Also, don''t agonize over what the url''s look like. You can use routes to map any kind of urls to any kind of controller structure.> > I would like to use a layout "template" for all the pages. How then, > if I''m using independent controllers for each page do I share a > layout?By default, all controllers will use the layout in app/views/layouts/application.rhtml. So put your template there and you''re done. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Add a line to routes.rb map.connect(":action/:id", :controller => "base_controller") On 9/13/07, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Well, all of the pages are pretty much standard, read an object from > the database then databind the page. SO that would fit into your one > controller idea with many actions for each page. > > I would like my urls to look like this: > > www.domain_name.com/products > www.domain_name.com/whitepapers > www.domain_name.com/about > > etc... > > Without any modifications to my routes.rb file the only way to access > my pages is to refrene the controller in the path like: > > www.domain_name.com/base/products > > How do I set up my urls to work like my list above? > > On Sep 13, 12:13 am, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > If your site is just HTML, > > > > then stick with one controller. > > > > or else split them like this > > > > base_controller => [home, press, about us] > > product_controller => [products] > > > > -- > > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---
One more thing: What you said takes care of most of the urls: www.domain_name.com/products www.domain_name.com/whitepapers www.domain_name.com/about but I would like to access whitepapers like this: www.domain_name.com/whitepapers/1 www.domain_name.com/whitepapers/3 ... www.domain_name.com/whitepapers/[WhitePaper.id] How would I set this url structure up? On Sep 13, 8:23 am, "Ryan Angilly" <angi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Add a line to routes.rb > > map.connect(":action/:id", :controller => "base_controller") > > On 9/13/07, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Well, all of the pages are pretty much standard, read an object from > > the database then databind the page. SO that would fit into your one > > controller idea with many actions for each page. > > > I would like my urls to look like this: > > >www.domain_name.com/products > >www.domain_name.com/whitepapers > >www.domain_name.com/about > > > etc... > > > Without any modifications to my routes.rb file the only way to access > > my pages is to refrene the controller in the path like: > > >www.domain_name.com/base/products > > > How do I set up my urls to work like my list above? > > > On Sep 13, 12:13 am, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > If your site is just HTML, > > > > then stick with one controller. > > > > or else split them like this > > > > base_controller => [home, press, about us] > > > product_controller => [products] > > > > -- > > > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---
It should already work. params[:id] should contain the 1 or the 3 in the examples you gave. then in the controller you''d do something like wp = WhitePaper.find_by_id(params[:id].to_i) On 9/13/07, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > One more thing: > > What you said takes care of most of the urls: > > www.domain_name.com/products > www.domain_name.com/whitepapers > www.domain_name.com/about > > but I would like to access whitepapers like this: > > www.domain_name.com/whitepapers/1 > www.domain_name.com/whitepapers/3 > ... > www.domain_name.com/whitepapers/[WhitePaper.id] > > How would I set this url structure up? > > On Sep 13, 8:23 am, "Ryan Angilly" <angi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Add a line to routes.rb > > > > map.connect(":action/:id", :controller => "base_controller") > > > > On 9/13/07, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Well, all of the pages are pretty much standard, read an object from > > > the database then databind the page. SO that would fit into your one > > > controller idea with many actions for each page. > > > > > I would like my urls to look like this: > > > > >www.domain_name.com/products > > >www.domain_name.com/whitepapers > > >www.domain_name.com/about > > > > > etc... > > > > > Without any modifications to my routes.rb file the only way to access > > > my pages is to refrene the controller in the path like: > > > > >www.domain_name.com/base/products > > > > > How do I set up my urls to work like my list above? > > > > > On Sep 13, 12:13 am, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > wrote: > > > > If your site is just HTML, > > > > > > then stick with one controller. > > > > > > or else split them like this > > > > > > base_controller => [home, press, about us] > > > > product_controller => [products] > > > > > > -- > > > > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter wrote:> On 9/13/07, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> I want to make a simple website with rails, but I''m confused about how >> to setup my controllers. Here''s what I want: >> >> 5 pages: Home, Products & Services, Press Center, White Papers & About >> us >> >> So, I''m confused about how to set this up. Should each page have it''s >> own controller, e.g.: >> >> home_controller, products_controller, press_controller, >> white_papers_controller and about_us_controller >> >> Is this a wise design decision? >> > > Can''t tell, with the information given. > > The very "general" rule is to have a controller per model, so that''s a > good place to start. But it''s not necessary to agonize over the > structure of your controllers. Rather than trying to envision how the > whole thing will look like when it''s done, just implement a very small > part of it. Start with one controller. Then when you need to add > stuff, you have a choice: do I add an action to my current controller > or do I create a new controller? Well, make your best guess and see > how that goes. If it turns out to be problematic for whatever reason, > it''s easy to back up and take the other direction. > > Also, don''t agonize over what the url''s look like. You can use routes > to map any kind of urls to any kind of controller structure. > > >> I would like to use a layout "template" for all the pages. How then, >> if I''m using independent controllers for each page do I share a >> layout? >> > > By default, all controllers will use the layout in > app/views/layouts/application.rhtml. So put your template there and > you''re done. >I know this reply is quite far down in the thread but have you considered using a Content Management System like Radiant? Based on the scarce requirements in the OP''s email, it would appear that if most of the pages are largely static (like a company website), Radiant would be quite good! Cheers, Mohit. 9/14/2007 | 12:52 AM. --~--~---------~--~----~------------~-------~--~----~ 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, it looks like it does. Thanks. It seems like the single controller with actions for each page will work fine for me. On Sep 13, 8:37 am, "Ryan Angilly" <angi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It should already work. params[:id] should contain the 1 or the 3 in the > examples you gave. > > then in the controller you''d do something like > > wp = WhitePaper.find_by_id(params[:id].to_i) > > On 9/13/07, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > One more thing: > > > What you said takes care of most of the urls: > > >www.domain_name.com/products > >www.domain_name.com/whitepapers > >www.domain_name.com/about > > > but I would like to access whitepapers like this: > > >www.domain_name.com/whitepapers/1 > >www.domain_name.com/whitepapers/3 > > ... > >www.domain_name.com/whitepapers/[WhitePaper.id] > > > How would I set this url structure up? > > > On Sep 13, 8:23 am, "Ryan Angilly" <angi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Add a line to routes.rb > > > > map.connect(":action/:id", :controller => "base_controller") > > > > On 9/13/07, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Well, all of the pages are pretty much standard, read an object from > > > > the database then databind the page. SO that would fit into your one > > > > controller idea with many actions for each page. > > > > > I would like my urls to look like this: > > > > >www.domain_name.com/products > > > >www.domain_name.com/whitepapers > > > >www.domain_name.com/about > > > > > etc... > > > > > Without any modifications to my routes.rb file the only way to access > > > > my pages is to refrene the controller in the path like: > > > > >www.domain_name.com/base/products > > > > > How do I set up my urls to work like my list above? > > > > > On Sep 13, 12:13 am, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > > wrote: > > > > > If your site is just HTML, > > > > > > then stick with one controller. > > > > > > or else split them like this > > > > > > base_controller => [home, press, about us] > > > > > product_controller => [products] > > > > > > -- > > > > > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---
Thanks, I''ll check it out. On Sep 13, 9:52 am, Mohit Sindhwani <mo_m...-RxrYI66vbj0AvxtiuMwx3w@public.gmane.org> wrote:> Bob Showalter wrote: > > On 9/13/07, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> I want to make a simple website with rails, but I''m confused about how > >> to setup my controllers. Here''s what I want: > > >> 5 pages: Home, Products & Services, Press Center, White Papers & About > >> us > > >> So, I''m confused about how to set this up. Should each page have it''s > >> own controller, e.g.: > > >> home_controller, products_controller, press_controller, > >> white_papers_controller and about_us_controller > > >> Is this a wise design decision? > > > Can''t tell, with the information given. > > > The very "general" rule is to have a controller per model, so that''s a > > good place to start. But it''s not necessary to agonize over the > > structure of your controllers. Rather than trying to envision how the > > whole thing will look like when it''s done, just implement a very small > > part of it. Start with one controller. Then when you need to add > > stuff, you have a choice: do I add an action to my current controller > > or do I create a new controller? Well, make your best guess and see > > how that goes. If it turns out to be problematic for whatever reason, > > it''s easy to back up and take the other direction. > > > Also, don''t agonize over what the url''s look like. You can use routes > > to map any kind of urls to any kind of controller structure. > > >> I would like to use a layout "template" for all the pages. How then, > >> if I''m using independent controllers for each page do I share a > >> layout? > > > By default, all controllers will use the layout in > > app/views/layouts/application.rhtml. So put your template there and > > you''re done. > > I know this reply is quite far down in the thread but have you > considered using a Content Management System like Radiant? Based on the > scarce requirements in the OP''s email, it would appear that if most of > the pages are largely static (like a company website), Radiant would be > quite good! > > Cheers, > Mohit. > 9/14/2007 | 12:52 AM.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could have home controller with subpages as actions. Like ../home/products ... with /home/index beeing default. But then again if you like more restful approach you could create all those controllers and put a single redirect_to into each one of them and stil have single (complicated) source file. If you have more controllers but want a single layout than name your layout ''application.rhtml''. This layout is valid for all controlers that do not have their own layout defined. by TheR -- 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-/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 -~----------~----~----~----~------~----~------~--~---