This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Rails for the poor Struts guys #2
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Brian has written his second part article, Rails for Struts-ters, Part 2: The Views.
As the title implies, he goes into detail, comparing the view side of Struts vs. Rails. If you grok Struts, you will understand the rails side from this.
It also clears some myths such as "Rails doesn't have SiteMesh capability" which I have heard from quite a few Java developers.
Rails Layouts
Final thing to look at in views is layouts.
The quasi-official tool for this in Struts is Tiles, but I prefer Sitemesh, so will use a sitemesh example.
Rails has Layouts, which are the same conceptually as Sitemesh decorators. Here is one
<html>
<head>
<title>Brian and Joy's Wedding</title>
<link href="/stylesheets/scaffold.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%= render_menu %>
<%= @content_for_layout %>
</body>
</html>
The layout gets wrapped around any rendered output, with the output going at the <%= @content_for_layout %> point.
The easiest way to use a layout for all views is to just have a layout named application.html, and it will be used implicitely.
You can explicitely use a layout by declaring it in the controller, a la
class GiftController < ApplicationController
layout 'scaffold'
before_filter :require_logged_in
which will have it look for scaffold.rhtml to use as a layout. Sitemesh uses an external XML file to configure these, under typical usage, but it is conceptually the same.
Great stuff Brian!