Where to put basic site pages?

I am new to RoR, so forgive me as I know this is fundamental, but what is the "standard" for creating basic site pages like: home, about, contact, etc. I definitely understand the MVC approach and therefore do not want to couple these pages with other components. My guess is to create a "site" controller to manage these types of pages... Not sure, so I wanted to get more direction before I make something harder.

Where do I put basic site pages? How do I map these in routes.rb so they appear as mysite.com/about, but do not conflict with other rules?

Thanks, Jason

Where do I put basic site pages?

I usually do have a general container controller - I like to call it 'home'

How do I map these in routes.rb so they appear as mysite.com/about, but do not conflict with other rules?

You can create them and put them in your public directory - Rails will look there first.

For example if you have an 'about' controller and you create an about directory and create test.html in there you can then go to /about/ test

Hope that helps. John

Thanks for the response. I am looking for something a bit more elegant as far as the routes. I don't want to go to home/about or home/ contact. I understand the general container controller and will adopt that practice. However, I am wondering if I can make a default rule that would allow me to go to /about, /contact, etc and they map accoardingly to the :controller => "home" as "home/:action".

So I guess the question now is, can anyone tell me how to write that rule?

in the cong directory you have a routes.rb archive there yo can arrange your routes, the default are for each controler a route is created containing the destroy, create, new , update .

For example if you have a home controller this will be created:

map.resources :home , this will let you access from your browser to /home/new home/edit/id home/ (the index), each of this will have a view related.

Thanks for the reponse. I undertand the controller routing. But this is not the functionality I am after.

I want a route, that defaults to a "home" controller, but doesn't interfer with other routes. In addition, it would allow me to use URLs like /about /contact, not /home/about, /home/contact.

I usually use the method shown in

with the route being map.static ':permalink', :controller => 'pages', :action => 'show'

placed right above the default routes

You'll need to add this route to your routes.rb file:

map.home "home", :controller => "MyMiscController", :action => "mi_home_action" map.about "about", :controller => "MyMiscController", :action => "mi_about_action"

You will have now:

home_path (/home) about_path (/about)

helper methods so you can link them from your view files.

I can't think of other way.

Regards, Jorge Corona.

This is a great reply, Pazole. I think it's exactly what was needed and also helps to serve as a good example for reference. Thanks!

You could even glob the view directory for your general controller for view files and create the routes dynamically. E.g. put this in your routes.rb:

  ActionController::Base.view_paths.each do |path|     Dir.glob("#{path}/pages/*").each do |view_file|       view_name = File.basename(view_file, '.html.erb')       map.send view_name.to_sym, view_name, :controller => 'page', :action => view_name     end   end

(assuming your general controller is called "pages")

Cheers, Christian

Thanks to everyone for the replies. Extra thanks to Christian and Jorge, these are exactly what I was after. Also a good screencast from jjburka.