question on layouts

Hey all, Does any have suggestions to whether I should create a controller for every web page on my site or just create an action for every web page in same controller if those actions will never require database calls? It doesn't make sense to create a controller/model for a single web page if it isn';t going to require sql. However, I do need the url to actual show the different page just as in any site. So I'm just curious what are best practices to approach this. Thanks for any response.

write the function @ application_controller that can be access in any controller. for more info read abt application controller doc.

nirosh

nirosh wrote:

write the function @ application_controller that can be access in any controller. for more info read abt application controller doc.

nirosh

Hey thanks for the response. What about the image paths. This is in css and it's not linking to the images folder: background: #b8e5d1 url(/public/images/mastgrad.png) top left no-repeat;

public/images incorrect path? I don't understand because it looks like thats the path structure in my app.

nirosh wrote:

write the function @ application_controller that can be access in any controller. for more info read abt application controller doc.

Or create a utility controller, call it "home" or whatever, that handles all the non-model pages you need. That's pretty typical.

What about the image paths. This is in css and it's not linking to the images folder: background: #b8e5d1 url(/public/images/mastgrad.png) top left no-repeat;

public/images incorrect path? I don't understand because it looks like thats the path structure in my app.

"public" is the root directory of all the static resources -- so you only want to use `background: #b8e5d1 url( /images/mastgrad.png ) ...`

HTH,

John Merlino wrote:

Hey all, Does any have suggestions to whether I should create a controller for every web page on my site or just create an action for every web page in same controller if those actions will never require database calls?

Do neither. Use a single controller action for your static pages, and give it the name of the page as a parameter.

It doesn't make sense to create a controller/model for a single web page if it isn';t going to require sql.

That's poor reasoning.

However, I do need the url to actual show the different page just as in any site. So I'm just curious what are best practices to approach this. Thanks for any response.

You can use routing to make the URLs be anything you like.

Best,

If the OP is, in fact, talking about static pages, you might consider, for performance reasons, putting them in a structure under /public and letting Apache, et.al. deliver them without the involvement of mongrel / passenger / your rails app.

HTH, Bill

I understand the idea of having apache serving static content but anyways what do you think about this as i am with similar question in mind.

#controller class HomeController < ApplicationController

  def index     page = params['page']

    if page       begin

        # page var is the same as the name of my "page.html.erb" as in about.html.erb to process a param with value about etc..         render "page_views/" + page

      rescue ActionView::MissingTemplate

        render "errors/404.html", :status=> 404

      end     end

  end

end #end of class

#router as the last 2 lines after all options have been excluded

match '/:page' => 'home#index' , :as=> :page root :to => "home#index"

Would this be good practice? Might be raw but it does the job for my needs.

What you think folks