This project is archived and is in readonly mode.

#3555 ✓invalid
Sam Ruby

Remove railties/.../scaffold_generator.rb: template "layout.html.erb"

Reported by Sam Ruby | December 9th, 2009 @ 12:54 PM | in 3.0.2

Rails has the ability to share layouts between controllers, primarily by repeating "layout 'application'" in each controller. This isn't very DRY.

Common techniques to refactor this out (such as inheritance) are thwarted by the fact that scaffold generator produces a new layout for each controller, and such (often unwanted) templates will be chosen first, over the expressed wishes of the superclass. This behavior is surprising and complicates teaching. Agile Web Development with Rails, Edition 3, for example, has taken the approach of establishing a common layout for the Depot application and then instructing the reader to delete the generated layout after each and every call to the scaffold generator.

My suggestion is that Rails::Generators::AppGenerator produce a single layout based on the application name and reference it in application_controller. This may create migration concerns, so perhaps scaffold_generator should continue to produce controller-specific layouts, but only if ApplicationController.instance_eval('@_layout') is nil.

I'm willing to write patches, test the code, whatever; but first I'm seeking agreement on what the desired behavior should be.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages