Sorry - I completely misunderstood you Damon. I thought you were
giving me ERb when you were actually using JS. This is what happens
when you miss the first half of the thread! Sorry for chasing the
rabbit trail.
Like Jarkko implied, the helper methods are just an easier method for
creating static HTML. It looks like your HTML is going to be static
(not dependent on server-side info)–thus, the HTML generated will be
the same whenever that button is clicked; it would just add a new row
to the PO with the same HTML.
In that case, the best option would probably be to throw all that ERb
code in a view (temporarily), render it, do a “View Source” on the
rendered page, and throw the static HTML in your Javascript code.
Thus you would have something like this:
var completeRow = '
<input type=“text”
name="purchase_order_detail[quantity]
id=“purchase_order_detail_quantity” size=“5” /> | … ';
However, something like what I recommended earlier might work (though
it might violate MVC separation):
–(controller)
@completeRow = render_to_string(:inline => '<td…><%= text_field… %
')
–(view)
function addRow {
var completeRow = ‘<%= @completeRow %>’;
new Insertion.Bottom(…);
}
That way would give you the advantage of still having the ERb code in
your codebase, but it throws views in your controller, which is kind
of ugly.
Jarkko is right, though–with JS you’re dealing with client-side code
only. If your added row is dependent on runtime data, you’ll need to
do an AJAX call or something similar. But Prototype makes that
easy… you’d just need an AJAX.Updater.
On another note… do you run into problems having the same HTML ID
repeated on multiple products? I’m not quite familiar with
Insertion.Bottom, but it looks like every Weight field, Description
field, and the like would have the same ID. Technically that’s
illegal under XHTML, but I don’t know if it will actually cause
problems. I remember some thread on the Rails list about ways to deal
with this, but I’m not sure what the outcome was.
Hope this helps!
Brad E.
866-EDIGERS