On Nov 3, 2011, at 8:46 PM, hobo_hippy wrote:

> 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

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

-- 
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