Generic-user-small 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

 
Generic-user-small 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

 
Generic-user-small 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”
map.root :controller => ‘pages’

Any advice would be appreciated.

Thanks -wg

 
Generic-user-small 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:
1) Declare the OrganizationsController class; i.e. add organizations_controller.rb to the controllers directory.
2) Code the about view; i.e. add an organizations sub-directory to the views directory, then create an about.html.erb file here. Put in the desired html/ruby code.
3) Update the routing; i.e. the routes.rb file in the config directory. Add in the following: map.connect ‘about’, :conditions => { :method => :get }, :controller => “organizations”, :action => “about”

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.

 
Generic-user-small 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)

 
Generic-user-small 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.

 
M_v_shokhirev_small 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…

 
M_v_shokhirev_small 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’
map.root :controller => ‘pages’

(2) delete the public/index.html
(3) create the app/controllers/pages_controller.rb WITHOUT actions
(3) create the app/views/pages/about.html.erb and app/views/pages/contact.html.erb templates

you’ll get the needed dynamic “Views without actions”!

8 posts, 4 voices