Form Name or ID

Hi all:
I have a form and I want to use the same code for “new” and “edit”
methods rendering the view code in a partial.

This view code is working for the “new” method but do not for the
“edit”, cause of the name of the form object.

Code for the New View
<%= render :partial => “order_form” %>

<%= link_to ‘Back’, order_path %>

Code for the Edit View (same as new…)
<%= render :partial => “order_form” %>

<%= link_to ‘Back’, order_path %>

Code for the partial View “_order_form”

<% form_for(@order) do |f| %>

<%= observe_field ‘order_field1’, :url => {:action =>
‘calculate’}, :with => “Form.serialize(‘new_order’)” %>

<% end %>

The observe field only works for the “new” because the “hardcoding”
parameter name of the form.
For new object the name of the form is “new_order”, for editing is
“edit_order_19” (19 is an ID for the “order” object)
The name of the form is depending of the object the view is editing
and I need the name for the Observe_field work properly in all
records.
How can I pass the name of the form as a variable to the controller ?

Thanks
FF

FF wrote:
[…]

For new object the name of the form is “new_order”, for editing is
“edit_order_19” (19 is an ID for the “order” object)
The name of the form is depending of the object the view is editing
and I need the name for the Observe_field work properly in all
records.
How can I pass the name of the form as a variable to the controller ?

You don’t need to. Pass it in :locals when you render the partial.

Thanks
FF

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I need all the form values for the field in the observe_form call. …
… Form.serialize(‘new_order’)…
because the controller must to do some calcs and refresh the form with
the results

Can you explain how I shoud to use :locals variable ?
Thanks,
FF

On 28 sep, 19:44, Marnen Laibow-Koser <rails-mailing-l…@andreas-

FF wrote:

I need all the form values for the field in the observe_form call. …
… Form.serialize(‘new_order’)…
because the controller must to do some calcs and refresh the form with
the results

Can you explain how I shoud to use :locals variable ?

Easy. Just put Form.serialized(object_name) in the partial instead of
hard-coding. Then you can do :locals => {:object_name =>
‘edit_order_19’} or whatever. Remember, it’s just a string.

Thanks,
FF

On 28 sep, 19:44, Marnen Laibow-Koser <rails-mailing-l…@andreas-

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]