On Jan 10, 2012, at 9:31 PM, hobo_hippy wrote:
> Ok. I'm getting the custom form to do almost everything I need it to.
> Only problem is I don't want the user to have to specify what item
> they're adding (a belongs to association of the model). I'm writing
> the form in a repeat block where the local context is the item I want
> add. Something like
>
> <repeat with="&@foods">
> <%= this.name %>
> <%= this.price %>
>
> <form with="&OrderAssist.create">
> <field-list fields="toppings, food"/>
> <submit label="add"/>
> </form>
>
> </repeat>
>
> so i figured there must be some way to pass the current food id to the
> OrderAssist. However, I feel like the local context would get jumbled
> because inside the form "this" would refer to the OrderAssist, not the
> food.
>
> How do I pass the current food from the repeat to the OrderAssist i'm
> creating rather than making a user choose a food from a select button?
If you've got a belongs_to relation between OrderAssist and Food, thus:
class Food
has_many :order_assists
end
class OrderAssist
belongs_to :food
end
then you can do this:
<repeat with="&@foods">
<form with="&this.order_assists.build">
<% in here, this.food should be set correctly. <form> will (I believe) even
create a hidden-field for it if you don't mention it in the field-list %>
</form>
</repeat>
You probably don't want to use OrderAssist.create in any case - that spams
unattached records into your DB...
--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.