Views

Different places views are stored…

The view for a particular action is usually built using 2 files.

  • The file associated with the action, typically app/views/my_controller/action.rhtml
  • and the layout file, typically app/views/layouts/my_controller.r[html|xml]

The layout file will contain a yield :layout that includes the output of the file associated with the action. :layout is the defayult content returned so yield will do without the parameter

If there is a file called application.r[html|xml] in the layouts folder then this will be applied to all the controllers that don’t have a layout defined for them. The layout can be overridden by a layout declaration in the file controller file. ie This will look for a file called non_standard_layout.r[html|xml] in app/views/layouts and use that instead of the default layout file:
[code]
class MyController < ApplicationController layout "non_standard_layout" # ... end [/code] If the parameter to layout is a symbol it is taken to be the name of a controller instance method that returns the name of the layout to be used ie: [code] class StoreController < ApplicationController layout :determine_layout # ... private def determine_layout if Store.is_closed? "store_down" else "standard" end end end [/code] Actions can also render a specific layout with a render call like these: [code] def rss render(:layout => false) # never use a layout
end
def checkout
render(:layout => “layouts/simple”)
end

[/code]
Subclasses of a controller will use that controllers layout unless it is overridden with a layout statement.

You must be logged in to post a comment.