On Sun, Sep 13, 2009 at 2:05 PM, Dudebot <[email protected]> wrote:
> > Thanks, Eric. What I'm struggling with is how to set a variable, > rather than get one. What would be the proper form for setting > SomeObject.amount? > > Thanks for the correction on "This". Old habits die hard :) > > On Sep 13, 3:59 pm, Eric <[email protected]> wrote: > > Text fields don't take actions, they're just text fields with some > > optional aesthetics. put :amount in there, and if item.amount exists, > > it will be filled in. > > > > http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html... > > > > Also, ruby doesn't use This, it's "self." > > > > There may be other problems in find_cart and add_item. > > > > On Sep 13, 12:30 pm, Dudebot <[email protected]> wrote: > > > > > > > > > Sorry for this basic noob question: > > > > > I have an "Item" class in my models which corresponds to a SQL table, > > > and a "Cart" class and a "CartItem" class which do not. The Item > > > class does not have an amount object, which is transitory, so I've put > > > this amount object in my CartItem class: > > > > > class CartItem > > > > > attr_reader :item, :amount > > > > > def initialize( item ) > > > @item = item > > > end > > > > > def set_amount( amount ) > > > This.amount = amount > > > end > > > > > end > > > > > I have a list of items in a viewer form, and I'd like to pass > > > associated amount to my CartItem when the user hits the "Add to Cart" > > > button. I've tried many variations of text_field and text_field_tag > > > in: > > > > > <% @items.each do |item| %> > > > ... > > > <%= text_field( :amount , :action => 'set_amount( > :amount )', :id => > > > item )%> > > > <%= button_to "Add to Cart" , :action => 'add_to_cart', > :id => item > > > %> > > > ... > > > <% end %> > > > > > I know the text_field up there is severely mangled and won't work--but > > > it's an example of the 2000th try, the last several hundred out of > > > pure desperation. Can anyone help with the proper syntax for the > > > text_field in the .html.emb file? > > > > > The add_to_cart call with the button is working: > > > > > def add_to_cart > > > item = Item.find( params[ :id ] ) > > > @cart = find_cart > > > @cart.add_item( item ) > > > end > > > > > Many TIA, > > > Craig > <%= text_field( :amount, :value => some_value, :id => item ) %> -Conrad > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" 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/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

