update="foo" woes

43 views
Skip to first unread message

hobo_hippy

unread,
Nov 3, 2011, 8:46:42 PM11/3/11
to Hobo Users
I've been reading around a bit on this topic, but I can't find a clear
answer to the problem I'm running into. In short, i'm getting a
horrible ajax error message after clicking a create button with
update="foo" declared. I've also tried wrapping the create button in a
<form update="foo"> ... </form>, but the same thing happens! please
read on...

I understand the idea of labeling parts of your site with part="foo"
such that on form submissions (for example) I can add the update
attribute such as update="foo" to avoid having to refresh the page to
display new information. This is great! Without having to deal with a
bunch of java or ajax, I can update information on the page after
submitting a form. However, I'm having some serious difficulties with
this. Allow me to explain my setup:

I've got this custom show page for my Menu model (I'm only showing the
pertinent part below) where I replace the automagic aside:

<show-page>

...bunch of stuff...

<aside: replace>
<div id="yourOrder">
<h1> <%= @user %>'s Order </h1>
<collection with="&@assists" part="foo">
<h4> <%= this.item.name %> </h4>
<delete-button label="remove" confirm="This will remove this
item from your order. Are you sure?"/>
</collection>
<h4> total: <%= @cost %> </h4>
</div>
</aside:>

</show-page>

And here's some controller actions I've setup inside my menus
controller

def show
@myOrder = Order.find :first, :conditions => {:user_id =>
current_user}
@myItems = @myOrder.items.apply_scopes(:order_by => :name)
@cost = @myItems.sum("price")
@orderCount = Order.find :all, :conditions => {:user_id =>
current_user}
@assists = OrderAssist.find :all, :conditions => {:user_id =>
current_user}
end

Now I should mention my Menus have children called items and through
hobo-magic (I know it's not magic, i just like calling it that :) a
collection of the menu's items is shown on the menu show page. I've
edited the cards for these items as follows -- in my application.dryml
I've got this:

<extend tag="card" for="Item">
<old-card merge>
<h5><a><view:name/></a> Price: $<view:price/>0 </h5>
<h6><view:description/></h6>
<create-button:order_assist update="foo" message="adding
#{this.name} to your order. Please wait for the page to update..."
label="add"/>
</old-card>
</extend>

To be clear, let me explain the pertinent model associations:
Menus have many items

Items have many order_assists and items have many orders through
order_assists

Orders belong to user, have many items

(to skip a bunch of obvious stuff, i'm just gonna say the through
association works fine, the above listed associations are the
important ones)

So, to get to the fun bit, If i click on the create button on the card
for item, an order assist is created linking the item to a user and
order. I had to customize the create action in the order_assist
controller to make sure all the info gets saved to the order assist
automagically. In the order_assist controller:

def create
hobo_create do
@user = current_user
@myOrder = Order.find :first, :conditions => {:user_id =>
current_user}
this.order_id = @myOrder.id
hobo_update
end
end

So far so good! At this point I should mention the delete-button is
really cool! I can click the button and not only does it remove the
order_assist, but it updates that part of the page with some beautiful
ajax goodness and fades the order_assist away. At this point I wanted
to NOT have to refresh the page after creating an order_assist with
the create button. So I tried out the part="foo" and update="foo"
functionality. It looked like this:

recall (or look above again) my collection in the aside is as
follows:

<collection with="&@assists" part="foo"> #part="foo" being the
important bit


and the create button in the item card is as follows:

<create-button:order_assist update="foo" message="adding #{this.name}
to your order. Please wait for the page to update..." label="add"/>

So when you click create, to the best of my understanding, hobo tries
to update the foo part of the page. However, when I tried this out, I
get some horrible error showing up in what looks like an ajax error
message.
The error is as follows:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Action Controller: Exception caught</title>
<style>
body { background-color: #fff; color: #333; }

body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>
</head>
<body>

<h1>
NoMethodError
in Order assistsController#create
</h1>
<pre>You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?</pre>


<p><code>Rails.root: /Users/gir/Sites/levelz/yinzDeliver</code></p>

<div id="traces">
<a href="#" onclick="document.getElementById('Framework-
Trace').style.display='none';document.getElementById('Full-
Trace').style.display='none';document.getElementById('Application-
Trace').style.display='block';; return false;">Application Trace</a> |
<a href="#" onclick="document.getElementById('Application-
Trace').style.display='none';document.getElementById('Full-
Trace').style.display='none';document.getElementById('Framework-
Trace').style.display='block';; return false;">Framework Trace</a> |
<a href="#" onclick="document.getElementById('Application-
Trace').style.display='none';document.getElementById('Framework-
Trace').style.display='none';document.getElementById('Full-
Trace').style.display='block';; return false;">Full Trace</a>

<div id="Application-Trace" style="display: block;">
<pre><code>app/views/menus/show.dryml:19:in `foo_part'
app/views/menus/show.dryml:19:in `foo_part'
app/controllers/order_assists_controller.rb:12:in `create'
app/controllers/order_assists_controller.rb:8:in `create'</code></pre>
</div>
<div id="Framework-Trace" style="display: none;">
<pre><code>hobo (1.3.0.RC2) lib/hobo/rapid/taglibs/
rapid_generics.dryml:36:in `collection'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:327:in
`_tag_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:268:in
`new_object_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:249:in
`new_context'
actionpack (3.0.1) lib/action_view/helpers/capture_helper.rb:171:in
`with_output_buffer'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:249:in
`new_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:256:in
`new_object_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:327:in
`_tag_context'
hobo (1.3.0.RC2) lib/hobo/rapid/taglibs/rapid_generics.dryml:35:in
`collection'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:249:in
`new_context'
actionpack (3.0.1) lib/action_view/helpers/capture_helper.rb:171:in
`with_output_buffer'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:249:in
`new_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:168:in `send'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:168:in
`refresh_part'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:268:in
`new_object_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:249:in
`new_context'
actionpack (3.0.1) lib/action_view/helpers/capture_helper.rb:171:in
`with_output_buffer'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:249:in
`new_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:256:in
`new_object_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:185:in
`with_part_context'
dryml (1.3.0.RC2) lib/dryml/template_environment.rb:167:in
`refresh_part'
hobo (1.3.0.RC2) lib/hobo/controller.rb:86:in `ajax_update_response'
hobo (1.3.0.RC2) lib/hobo/controller.rb:81:in `each'
hobo (1.3.0.RC2) lib/hobo/controller.rb:81:in `ajax_update_response'
actionpack (3.0.1) lib/action_view/helpers/prototype_helper.rb:152:in
`instance_exec'
actionpack (3.0.1) lib/action_view/helpers/prototype_helper.rb:152:in
`initialize'
actionpack (3.0.1) lib/action_view/helpers/capture_helper.rb:171:in
`with_output_buffer'
actionpack (3.0.1) lib/action_view/helpers/prototype_helper.rb:151:in
`initialize'
actionpack (3.0.1) lib/action_controller/metal/renderers.rb:92:in
`new'
actionpack (3.0.1) lib/action_controller/metal/renderers.rb:92:in
`_render_option_update'
actionpack (3.0.1) lib/action_controller/metal/renderers.rb:32:in
`_handle_render_options'
actionpack (3.0.1) lib/action_controller/metal/renderers.rb:47:in
`render_to_body'
actionpack (3.0.1) lib/action_controller/metal/compatibility.rb:55:in
`render_to_body'
actionpack (3.0.1) lib/abstract_controller/rendering.rb:101:in
`render_to_string'
actionpack (3.0.1) lib/abstract_controller/rendering.rb:92:in `render'
actionpack (3.0.1) lib/action_controller/metal/rendering.rb:17:in
`render'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:
40:in `render_without_hobo_model'
activesupport (3.0.1) lib/active_support/core_ext/benchmark.rb:5:in
`ms'
/opt/local/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.1) lib/active_support/core_ext/benchmark.rb:5:in
`ms'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:
40:in `render_without_hobo_model'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:
78:in `cleanup_view_runtime'
activerecord (3.0.1) lib/active_record/railties/controller_runtime.rb:
15:in `cleanup_view_runtime'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:
39:in `render_without_hobo_model'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:813:in `render'
hobo (1.3.0.RC2) lib/hobo/controller.rb:79:in `ajax_update_response'
hobo (1.3.0.RC2) lib/hobo/controller.rb:63:in `hobo_ajax_response'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:611:in `update_response'
actionpack (3.0.1) lib/action_controller/metal/mime_responds.rb:192:in
`call'
actionpack (3.0.1) lib/action_controller/metal/mime_responds.rb:192:in
`respond_to'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:603:in `update_response'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:593:in `hobo_update'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:429:in `response_block'
actionpack (3.0.1) lib/action_controller/metal/mime_responds.rb:192:in
`call'
actionpack (3.0.1) lib/action_controller/metal/mime_responds.rb:192:in
`respond_to'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:425:in `response_block'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:562:in `create_response'
hobo (1.3.0.RC2) lib/hobo/controller/model.rb:519:in `hobo_create'
actionpack (3.0.1) lib/action_controller/metal/implicit_render.rb:4:in
`send_action'
actionpack (3.0.1) lib/action_controller/metal/implicit_render.rb:4:in
`send_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:150:in
`process_action'
actionpack (3.0.1) lib/action_controller/metal/rendering.rb:11:in
`process_action'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:18:in
`process_action'
activesupport (3.0.1) lib/active_support/callbacks.rb:455:in
`_run__982768899__process_action__524098549__callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:409:in `send'
activesupport (3.0.1) lib/active_support/callbacks.rb:409:in
`_run_process_action_callbacks'
activesupport (3.0.1) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.1) lib/active_support/callbacks.rb:93:in
`run_callbacks'
actionpack (3.0.1) lib/abstract_controller/callbacks.rb:17:in
`process_action'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:
30:in `process_action'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in
`instrument'
activesupport (3.0.1) lib/active_support/notifications/instrumenter.rb:
21:in `instrument'
activesupport (3.0.1) lib/active_support/notifications.rb:52:in
`instrument'
actionpack (3.0.1) lib/action_controller/metal/instrumentation.rb:
29:in `process_action'
actionpack (3.0.1) lib/action_controller/metal/rescue.rb:17:in
`process_action'
actionpack (3.0.1) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.1) lib/abstract_controller/rendering.rb:40:in
`process'
actionpack (3.0.1) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal/rack_delegation.rb:
14:in `dispatch'
actionpack (3.0.1) lib/action_controller/metal.rb:173:in `action'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in
`call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:62:in
`dispatch'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:27:in
`call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in
`recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:96:in
`optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in
`recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.1) lib/action_dispatch/routing/route_set.rb:492:in
`call'
actionpack (3.0.1) lib/action_dispatch/middleware/
best_standards_support.rb:17:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.4) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/params_parser.rb:
21:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/flash.rb:182:in
`call'
actionpack (3.0.1) lib/action_dispatch/middleware/session/
abstract_store.rb:149:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/cookies.rb:287:in
`call'
activerecord (3.0.1) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/
query_cache.rb:28:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.1) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.1) lib/active_record/connection_adapters/abstract/
connection_pool.rb:355:in `call'
actionpack (3.0.1) lib/action_dispatch/middleware/callbacks.rb:46:in
`call'
activesupport (3.0.1) lib/active_support/callbacks.rb:415:in
`_run_call_callbacks'
actionpack (3.0.1)


I don't see how I could be referencing a nil object...

I've read alot about the trouble of update and collections/repeats, so
I also tried updating at a higher level. I tried update="yourOrder"
where div id="yourOrder" wraps around the entire collection, and most
of the aside. (see way above in the <aside: replace> )

I'm really stuck on this and need the page to not require a full page
refresh after creating a new order_assist. Any ideas?

I also have a second question. you may have noticed I'm summing all
the items in a user's order with the @cost action in the controller.
To my understanding the controller actions (is actions the right word
here?) are evaluated when the page loads. Will an update on a part
cuase the controller actions to be evaluated again? In other words, if
I get the part update thing working, will @cost be recalculated as
well? If not what means should I use to be calculating this total
without a controller action?

I know this is alot to go through, so if anyone has taken a few
minutes to help me figure this out, I REALLY REALLY APPRECIATE YOU!



Sincerely,
HoboHippy


P.S. I'm running hobo 1.3.0.RC3






Matt Jones

unread,
Nov 3, 2011, 9:53:43 PM11/3/11
to hobo...@googlegroups.com

The tricky bit with the part mechanism is that it essentially just re-renders the chunk of dryml that it's updating - *with* whatever instance variables the new action sets. This works *great* when you're updating a model via AJAX on, say, a show page for that model. Not quite so good here...

I suspect you'll get the result you're looking for if you set @assists correctly in your create action - and similarly for the @cost variable, if it's inside of a part.

--Matt Jones

hobo_hippy

unread,
Nov 3, 2011, 10:23:21 PM11/3/11
to Hobo Users
okay, but what do you mean correctly set the @assists? I thought I was
correctly setting it.

(just another thought, skinny controller, fat model) would this be
better approached by achieving similiar functionality through model
functions? Can you suggest a reference for writing such model
functions?

HoboHippy

Matt Jones

unread,
Nov 4, 2011, 7:48:40 AM11/4/11
to hobo...@googlegroups.com

On Nov 3, 2011, at 10:23 PM, hobo_hippy wrote:

> okay, but what do you mean correctly set the @assists? I thought I was
> correctly setting it.
>

You're setting it in the show action, but the part update renders from the *create* action. Adding:

@assists = OrderAssist.find :all, :conditions => {:user_id => current_user}

to that action should make the nil error go away.

BTW, is there a reason why you're not just declaring User has_many :order_assists and getting them that way? The find :all stuff just looks strange.

--Matt Jones


hobo_hippy

unread,
Nov 5, 2011, 8:11:55 AM11/5/11
to Hobo Users
I'm still learning the right way to do things. I'm kinda hacking away
at it till I get it to work well enough. I'll look into what you
recommended!

Thanks,
HoboHippy

hobo_hippy

unread,
Nov 26, 2011, 4:23:42 PM11/26/11
to Hobo Users
I've looked into your suggestions, and yeah, i could just use a User
has many. In any case I got it working quite nicely and understand the
controller actions a little better. I've got one more question though:

So now my aside updates the total when the user clicks the create
button. sweet. I also have a delete-button for each assist that shows
in the order, but if you delete an assist, the total doesn't update.
this is obviously becuase there's noting telling the app to update the
part where the total is. My total sits outside of the collection tags
becuase I don't want a total to show up after every item, just once at
the bottom. But FRET! delete-button doesn't have an update parameter
for the tag. I thought, hey no problem. Just stick the delete-button
inside a form and pass update="partWithTheTotal" as a form param. But
this isn't working either...

thoughts?

On Nov 5, 7:11 am, hobo_hippy <87bee...@gmail.com> wrote:
> I'm still learning the right way to do things. I'm kinda hacking away
> at it till I get it to work well enough. I'll look into what you
> recommended!
>
> Thanks,
> HoboHippy
>
> On Nov 4, 7:48 am, Matt Jones <al2o...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Nov 3, 2011, at 10:23 PM, hobo_hippy wrote:
>
> > > okay, but what do you mean correctly set the @assists? I thought I was
> > > correctly setting it.
>

> > You're setting it in the show action, but the partupdaterenders from the *create* action. Adding:

hobo_hippy

unread,
Nov 26, 2011, 4:48:56 PM11/26/11
to Hobo Users
OK wow. Way off. Sorry!! Clearly delete-button allows ajax attributes
just not callbacks. So I can use an update param...

however I'm getting the following error in my log:

< NoMethodError (undefined method `sum' for nil:NilClass):
< app/views/menus/show.dryml:27:in `foo2_part'
< app/views/menus/show.dryml:27:in `foo2_part'

which to me suggests I have a problem similiar to before, so I'm
customized the hobo_destroy function in the assist controller
similiarly to my hobo_update correction I made last time. I'm taking a
small leap of faith becuase upon reading through the delete-button
source code, there's no mention of the destroy function, just :delete
method...

and Voila!! It works. :3


Lovin this stuff,
HoboHippy

On Nov 26, 4:23 pm, hobo_hippy <87bee...@gmail.com> wrote:
> I've looked into your suggestions, and yeah, i could just use a User
> has many. In any case I got it working quite nicely and understand the
> controller actions a little better. I've got one more question though:
>

> So now my aside updates the total when the user clicks the createbutton. sweet. I also have adelete-buttonfor each assist that shows


> in the order, but if youdeletean assist, the total doesn'tupdate.
> this is obviously becuase there's noting telling the app toupdatethe
> part where the total is. My total sits outside of the collection tags
> becuase I don't want a total to show up after every item, just once at
> the bottom. But FRET!delete-buttondoesn't have anupdateparameter
> for the tag. I thought, hey no problem. Just stick thedelete-button

> inside a form and passupdate="partWithTheTotal" as a form param. But

kevinpfromnm

unread,
Nov 26, 2011, 6:44:19 PM11/26/11
to hobo...@googlegroups.com
There is an update attribute, just not listed in the docs.

<def attrs='label, update, in-place, image, confirm, fade, subsite' tag='delete-button'>

Owen Dall

unread,
Nov 27, 2011, 10:33:23 AM11/27/11
to hobo...@googlegroups.com
HoboHippy,

Would you mind entering the relevant code solution in a new recipe so others can benefit:


Then enter the link in a post with text that will provide the ability for others to find the solution as well?

Thanks,

Owen




On Sat, Nov 26, 2011 at 6:44 PM, kevinpfromnm <kevinp...@gmail.com> wrote:
There is an update attribute, just not listed in the docs.

<def attrs='label, update, in-place, image, confirm, fade, subsite' tag='delete-button'>

--
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/-/5HlelrRPEFUJ.

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.



--
-Owen
 
Owen Dall, Chief Systems Architect
Barquin International

hobo_hippy

unread,
Nov 30, 2011, 2:52:50 PM11/30/11
to Hobo Users
Hey Owen,

Great idea!! This would be my first recipe... exciting!! I'll do it
this afternoon or tomorrow morning.

-HoboHippy

On Nov 27, 10:33 am, Owen Dall <od...@barquin.com> wrote:
> HoboHippy,
>
> Would you mind entering the relevant code solution in a new recipe so
> others can benefit:
>
> http://cookbook.hobocentral.net/recipes
>
> Then enter the link in a post with text that will provide the ability for
> others to find the solution as well?
>
> Thanks,
>
> Owen
>

Reply all
Reply to author
Forward
0 new messages