You just need to change one line:
control = formHelper.call(object, method, otherArgs)
to:
control = formHelper.call(object, method, *otherArgs)
That should expand the array of other args and pass them into the
formHelper.call.
On 3/1/06 2:51 PM, "Sam Livingston-Gray" <[EMAIL PROTECTED]> wrote:
> What I'm trying to do:
>
> Display a form in a table using Rails, using a more compact method
> than simply spitting out the HTML for the entire form. So if I've got
> a model called Client, which has a field called "active", and I want a
> checkbox displayed with the label "Active?", the scaffolding code
> gives me something like this (apologies if this renders oddly):
>
> <tr>
> <td><label for="client_is_human">Human?</label></td>
> <td><%= check_box 'client', 'is_human', {}, 'yes', 'no' %></td>
> </tr>
>
> This has a bit of duplication, and I'd like to be able to boil it down
> to something like this:
>
> <%
> def wrap_form_helper(label, formHelperSymbol, object, method, *otherArgs)
> # do magic
> end
> %>
>
> <%= wrap_form_helper 'Human?', :check_box, 'client', 'is_human', {},
> 'yes', 'no' -%>
>
>
> How I've tried to do this:
>
> def wrap_form_helper(label, formHelperSymbol, object, method, *otherArgs)
> formHelper = method(formHelperSymbol)
> control = formHelper.call(object, method, otherArgs)
> # wrap control in some table tags and return it
> end
>
> The above Method#call code works fine as long as I only pass the first
> four arguments. Any more than that and I get a message to the effect
> that Array#stringify_keys is undefined.
>
> I can, of course, do a big case statement on the arity of otherArgs
> and pass otherArgs[0], otherArgs[1], etc... but that's horribly wrong.
> (It's still better than building a string for eval(), though,
> considering that one of the arguments is a hash.)
>
> Can't really STFW for this because I'm not sure what I'm looking for.
> Is there some way to expand an array and send its elements to call()?
>
> Any help appreciated,
> -Sam
> _______________________________________________
> PDXRuby mailing list
> [email protected]
> IRC: #pdx.rb on irc.freenode.net
> http://lists.pdxruby.org/mailman/listinfo/pdxruby
_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby