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






-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to