Simply Helpful - Is it being used?

Hi –

On 3/12/07, Christos Z. [email protected] wrote:

…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


Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

On 12 Mar, 23:34, “David A. Black” [email protected] wrote:

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

Sorry, I meant this:

def new
@user = User.new
end

not create.

On Mar 12, 2007, at 3:20 PM, Bala P. wrote:

Resolved the simply helpful problem, if I have the line: @user =
User.create in the new method, I am able to use simply helpful
plugin without any problems.

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.


James S.

Hi –

On 3/19/07, [email protected] [email protected] wrote:

Sorry, I meant this:

def new
@user = User.new
end

not create.

Scroll back about 12 messages in this thread for some discussion of
this idiom :slight_smile:

David


Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)