Help with migrating a H1.3 app to H2 - replacing an <update-button>

31 views
Skip to first unread message

paulj...@gmail.com

unread,
Oct 19, 2012, 2:48:30 PM10/19/12
to hobo...@googlegroups.com
I have a 1.3 app that uses an <update-button> tag. I am planning to migrate the app to 2.0, so I see in the release notes that I need to replace the <update-button>.

The current tag using it is here:


Can I get some guidance on the best way to replace the <update-button> on line 11 with a 2.0-compatible construct?

Thanks!

Bryan Larsen

unread,
Oct 19, 2012, 2:52:16 PM10/19/12
to hobo...@googlegroups.com
Off the top of my head:

<form ajax>
<hidden-field:id/>
<hidden-field:pledged-date value="&Date.today"/>
<submit label="Yes"/>
</form>

Bryan
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/DGBla5zVWMQJ.
> To post to this group, send email to hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

paulj...@gmail.com

unread,
Oct 19, 2012, 2:56:37 PM10/19/12
to hobo...@googlegroups.com
Cool.

This would not work in 1.3, bcs. fo the Ajax keyword, right?

Bryan Larsen

unread,
Oct 19, 2012, 3:06:14 PM10/19/12
to hobo...@googlegroups.com
You can replace ajax with update="companyuserform-#{typed_id}" and it
should work on 1.3 too. Also on 1.3 it will be more difficult to get
it to display inline rather than using block styling.

Bryan
> https://groups.google.com/d/msg/hobousers/-/ZK_pRok6vNwJ.

paulj...@gmail.com

unread,
Nov 4, 2012, 10:45:36 PM11/4/12
to hobo...@googlegroups.com
OK, I implemented this today. It seems to work except for the Ajax updating. The problem seems to be that the typed_id is not being substituted into the id field.

The code for the H2 version is here:


and, as an example, the generated HTML is:

    (that HTML gets a little chewed up in Pastie, but I think it is parseable)

Any ideas about what might prevent typed_id from being generated?

Thanks so much!

Bryan Larsen

unread,
Nov 5, 2012, 9:00:14 AM11/5/12
to hobo...@googlegroups.com
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.

paulj...@gmail.com

unread,
Nov 5, 2012, 2:02:48 PM11/5/12
to hobo...@googlegroups.com
Wow, that is so thorough and clear and helpful.

Thank you very much.

paulj...@gmail.com

unread,
Nov 5, 2012, 7:04:18 PM11/5/12
to hobo...@googlegroups.com
And, it worked great. I used a variation on Option 1.
Reply all
Reply to author
Forward
0 new messages