Having an association called transaction is a bad idea as the accessor methods generated will overwrite the transaction method (which is used when saving)
Fred Sent from my iPhone On 11 Oct 2008, at 18:59, Chris Hickman <[EMAIL PROTECTED] > wrote: > > I have two models (Transaction and RentedItem). > > Transaction.rb > has_many :rented_items > has_many :inventories, :through => :rented_items > > def add(inventory_id) > items = rented_items.find_all_by_inventory_id(inventory_id) > inventory = Inventory.find(inventory_id) > if items.size < 1 > ri = rented_items.create(:inventory_id => inventory.id, > :amount => 1, > :price => inventory.price) > else > ri = items.first > ri.update_attribute(:amount, ri.amount + 1) > end > ri > end > > Controller > > def add > @inventory = Inventory.find(params[:id]) > @item = @transaction.add(@inventory.id) <= where @transaction is > set > in a before_filter > flash[:notice] = "Added <em>[EMAIL PROTECTED]</em>" > redirect_to :controller => "inventory", :action => "list" > end > > Problem > I dont receive any errors and when list in rendered I see the correct > flash[:notice]. In the add method inside Transaction.rb the object is > created and return but when I look in the database no record was > saved. > I am completely lost on why the record wont save but is being created. > > ***I even tried RentedItem.create(...) in the controller to remove all > confusion from the controller to model ... and it still wont work.*** > > Could someone point me in any direction? Thanks > -- > Posted via http://www.ruby-forum.com/. > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

