Views without actions?
Wayde Gilliam
15 posts
|
This is probably a stupid question … but is there a way to create views that don’t have a corresponding action? For example, if I want to have an ‘About Us’ and ‘Contact’ page in my application can I simply create an about.html.erb and contact.html.erb that users are automatically routed to when they navigate to http://localhost:3000/about and http://localhost:3000/contact respectively? What is the best way to handle such static resources? Thanks – wg |
James West
70 posts
|
Personally I would not regard contact and About Us pages to be static data especially if developing for a third party However to answer your question with my limited knowledsge gleaned almost solely from this bokk so far and based on the Architecture of Rails Applications chapter it shows clearly that all you need is a controller and a view. Controllers are .rb flles and virws are html.erb files. I would heartily recommend several walk throughs of the book, coding as you go. It has helped me tremendously and you would find the answers that you need Hope this helps |
Wayde Gilliam
15 posts
|
I guess what I’m asking is, “How do you specify a controller to be the default controller?” Thus far I have a pages controller with contact and about actions … so you can navigate as “localhost:3000/pages/about” and “localhost:3000/pages/contact.” What I’d like to do is make the pages controller the default so you can omit the ”/pages” from the urls. I did find a solution which seems to be working … don’t know if this is the best way to do it (perhaps the only way) or not. I haven’t seen anything in the book thus far that addresses this. Anyways, here’s what I put in my routes.db map.connect ’:action’, :controller => “pages” Any advice would be appreciated. Thanks -wg |
Marc van Eyken
3 posts
|
I don’t know about specifying a default controller, but I’ve found two ways to navigate to “localhost:3000/about”. For a static page, simply add about.html to your project’s public folder. For a more interesting page, I went with James West’s controller/view option: My Ruby on Rails knowledge is based on what I’ve picked up in the Agile Web Development pdf, so I may be leading you down the wrong path, but hopefully this helps. |
James West
70 posts
|
My point about this is that I would not want to have to change my customers web sites every time they moved or changed address or if they wanted to just say something different about themselves. This info could be stored in the database and displayed on the about me page with an admin option to update/change these details. Marc, I presume you could generate a new model or controller for this rathee than doing it manually as you seem to have done? At least that’s probably what I would do. Again my rails knowledge is limited, (Picked up through 4 iterations of the pdf) |
Marc van Eyken
3 posts
|
I agree with enabling users with the ability to maintain their own contact & company details. I think that we’ve come full circle back to one of Ruby on Rails original benefits, let it do most of the work for us. If we’re looking for a standard page displaying details from the database, such as customer name & address, then we can use the standard scaffolding. We can always add in extra views like ‘about us’ and/or ‘contact’ views. To get the “http://localhost:3000/about” navigation we simply need to adjust the ActionController::Routing details. |
Mikhail V. S...
19 posts
|
Wayde, “the best way to handle such static resources” is to make ‘em static: you may simply create the file public/about/index.html and access it by pointing the browser to http://localhost:3000/about – it works fine (at least in Firefox and Opera). But this will be a STATIC file, not a view… |
Mikhail V. S...
19 posts
|
But, Wayde, if you (1) put in your routes.db file the route to the default controller: map.connect ’:action’, :controller => ‘pages’ (2) delete the public/index.html you’ll get the needed dynamic “Views without actions”! |
8 posts, 4 voices
