Here's a simplification of your code.
<do with="something_else_completely">
<% @cu = CompanyUser.find(foo) %>
<div part="pledgeform" id="pledgeform-#{typed_id}">
<form with="&@cu" update="pledgeform-#{typed_id}">
,,,,
1: the typed_id for pledgeform is going to return the typed_id for
something_else
2: the typed_id for the form is not clear. Does it get evaluated
before or after the with= statement? You may know, but it's best to
assume that anybody else working with your code doesn't. I really
like do statements for changing contexts to make this clear.
3: When redoing the part, Hobo will set the context to
something_else, then try to switch it to @cu when it hits the form.
However, @cu won't be set, because it's set in a piece of code outside
the part. Only view code inside the part is run when the part is
redisplayed.
Option #1:
<% @cu = CompanyUser.find(foo) %>
<do with="&@cu">
<div part="pledgeform" id="pledgeform-#{typed_id}">
<form update="pledgeform-#{typed_id}">
,,,,
In this piece of code, the <% @cu = CompanyUser.find(foo) %> code only
runs once. Hobo remembers the id of the CompanyUser, and reloads it
from the database when resurrecting the part, so you're guaranteed to
get the same CompanyUser when redisplaying the part.
Option #2:
<% @cu = CompanyUser.find(foo) %>
<do with="&@cu">
<div part="pledgeform">
<form ajax>
,,,,
This is the same as option #1, except it takes advantage of some new
features in Hobo 2.0. See
http://cookbook-1.4.hobocentral.net/manual/changes20#multiple_parts
for more details.
If it's possible that you want a different @cu when redisplaying the
part, use a form similar to:
<do with="&nil">
<div part="pledgeform">
<% @cu = CompanyUser.find(foo) %>
<form with="&@cu" ajax>
,,,,
`do with="&nil"` outside of a part definition is a good pattern to use
so that Hobo doesn't go to the work of resurrecting a context that
you're immediately going to throw away.
If you're using this form, you have to take care to ensure that `foo`
has validity, either by defining it as a helper method, as a variable
inside your controller or by using part locals:
http://cookbook-1.4.hobocentral.net/manual/ajax#local_variables
cheers,
Bryan
>
https://groups.google.com/d/msg/hobousers/-/F8D1APAsmIUJ.