small medium large xlarge

Generic-user-small
02 Jul 2008, 22:36
Wayde Gilliam (18 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
03 Jul 2008, 14:37
James West (104 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
03 Jul 2008, 19:39
Wayde Gilliam (18 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

Hawk.5x4_pragsmall
25 Jul 2008, 18:56
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
27 Jul 2008, 17:25
James West (104 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)

Hawk.5x4_pragsmall
27 Jul 2008, 21:15
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_pragsmall
23 Aug 2008, 03:30
Mikhail V. Shokhirev (a.k.a. Mike Shock) (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_pragsmall
23 Aug 2008, 03:30
Mikhail V. Shokhirev (a.k.a. Mike Shock) (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”!

You must be logged in to comment