Thursday, May 1, 2008

new.html.haml and edit.html.haml form.html.haml

More often than not, new.html.haml and edit.html.haml are virtually identical. Well this is very un-rails-ish. So instead I delete new and edit views, and replace them with a single form view.

You can then use the following in your controller's new and edit methods to make them both use the form.html.haml template instead of their respective defaults:

render :template => 'controller/form'

Before rails 2.0 this would not have been a very elegant thing to do, but with the new form_for method, it assumes a restful implementation and will therefore submit to the appropriate create or update action. So without any extra code you can elegantly have just one form for both new and edit.

No comments: