Hi --
...ahem, I am assuming here that you have an 'edit' and a 'new' view
and thus...
<% form_for Person %> /* new.rhtml */
<% form_for @person %> /* in edit.rhtml */
If that is not the case in your apps, as it usally is in mine, then
ignore my suggestion; it would be of no help in your quest for a more
'likeable idiom'
The thing is, what SimplyHelpful does is it lets you use only one form:
<% form_for @person ... %>
and it decides what the form action is by querying @person as to
whether or not it is a new record. The crux of it is:
html_options = if object.new_record?
{ :class => dom_class(object, :new), :id =>
dom_id(object), :method => :post }
else
{ :class => dom_class(object, :edit), :id =>
dom_id(object, :edit), :method => :put }
end
So it's an alternative to having two forms (or two master forms that
share partials, or using variables to store the action names, or
whatever).
David
The thing is, what SimplyHelpful does is it lets you use only one form:
<% form_for @person ... %>
and it decides what the form action is by querying @person as to
whether or not it is a new record.
Yes, I was aware of that. In most of my apps the 'new' form looks
nothing like the 'edit' form, hence my suggestion.
html_options = if object.new_record?
I guess you could monkey patch the above with something like:
html_options = if object.respond_to?('new')
as a (probably incorrect?) way to catch if you have an instantiated
object, and then
def new
@person = Person
end
But then 'new' becomes even more 'unlikeable'. Hmm...
-christos
Are you sure that’s a good idea? It may well be creating a lot of empty entries in your database (if a user requests a form and then doesn’t complete it). And even if that never happens, it will be invoking any validations in your User model.
Whatever the conceptual rights or wrongs of using User.new in the new method, it has a lot less performance implications than using create.
James.
Sorry, I meant this:
def new
@user = User.new
end
not create.