create-button fields help

14 views
Skip to first unread message

hobo_hippy

unread,
Oct 25, 2011, 2:36:07 AM10/25/11
to Hobo Users
I want to create a new order assist... Hooray! I've done it. Now for
the specifics:

OrderAssist
belongs_to :item
belongs_to :order

I'm creating the OrderAssist from within an item's card, so i an get
the item's id with #{this.id}
I can identify the current user's order with a controller action, so
@userOrder.id give me the user_id
so how do i pass these two pieces of information to the user_id and
order_id fields of OrderAssist? i've blindly guessed as below, but it
throws errors....

<extend tag="card" for="Item">
<old-card merge>
<h5><a><view:name/></a> Price: $<view:price/>0 </h5>
<h6><view:description/></h6>
<form>
<create-button model="OrderAssist" update="OrderAssists"
message="adding #{this.name}" label="Add to Order" fields="user_id =>
#{this.id}, order_id => @userOrder.id"/
>
</form>
</old-card>
</extend>


so what's the correct syntax for passing field values?

hobo_hippy

unread,
Oct 25, 2011, 2:41:35 AM10/25/11
to Hobo Users
searching through the posts here @ hobo users, I've found examples
suggesting the following is the correct syntax, however it throws an
error as well

fields="{item_id=>#{this.id}, order_id=>@myOrder.id}"

Error is:
unknown attribute: {item_id=>1, order_id=>@myOrder.id}

kevinpfromnm

unread,
Oct 25, 2011, 12:01:13 PM10/25/11
to hobo...@googlegroups.com
I haven't used create-button myself but a glance at the source suggests it might be easier to change the context to the association.  Then drop the model and fields arguments (creator is handled).

<create-button:order_assists update="OrderAssists" message="adding #{this.name}" label="Add to Order" />

I took a guess as to your association name.

hobo_hippy

unread,
Oct 25, 2011, 9:06:51 PM10/25/11
to Hobo Users
It looks like you dropped model="OrderAssist" and changed create-
button to create-button:order_assist.

I tried this out, and voila - the item gets passed to the order
assist! This is really cool. Though I don't really understand why
that's happening. And that's only half the problem still. I'm guessing
that hobo is picking up the old context of the item and passing it
along to the order assist (really neat!), however, the only way I can
grab the current user's order_id is through a controller action,
namely i've defined @myOrder to find that id. So how do I pass that to
the order assist? I still need to understand the fields"" syntax.

I'm guessing it would be something like what I've fond here:

http://cookbook.hobocentral.net/manual/multi_model_forms#model_support

so I'll be playing around with that sort of syntax hoping to stumble
into getting it working :P

Thanks! and any more advice would be great.
-hoboHippy

kevinpfromnm

unread,
Oct 26, 2011, 3:37:27 PM10/26/11
to hobo...@googlegroups.com
when you don't provide a model, it falls back to trying to guess what the item is via the current context.  the :order_assists changes the context to the association order_assists.  From that and the field parent (your original order or item), it sets that part of the association.  It also sets current_user for a creator association if available.

hobo_hippy

unread,
Oct 29, 2011, 10:21:24 PM10/29/11
to Hobo Users
thanks! that's much clearer now! But I'm still having trouble passing
values to other fields within the new instance of the order_assist. I
still can't figure out the correct syntax to set other fields!

again, i'm trying to do set some fields for the new order_assist with
the create button attribute, fields

something like:

fields="order_id=>1"

this of course is not working. I think it's becuase what I really want
to do is set an association, not set a field. Is doing that really any
different? Please help! I've been stuck on this for days.

hobo_hippy

unread,
Oct 31, 2011, 8:36:54 PM10/31/11
to Hobo Users
Since no one seemed to be able to help, and I had no luck guessing the
syntax, I took a different approach. I instead modified the create
action in the controller with a hobo_create do ... end.

It looked something like this:

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

This works! Though I'm sure there's a cleaner way to do it.

-HoboHippy
Reply all
Reply to author
Forward
0 new messages