Hi Werner,
das müsste so klappen.
class CartItem
end
cart = Array.new
ci1 = CartItem.new
ci2 = CartItem.new
ci3 = CartItem.new
cart << ci1
cart << ci2
cart << ci3
puts cart.inspect
cart.delete(ci2)
puts cart.inspect
Lg
Guido
------------------------------------
Guido Pesch
In der Mulde 2 - 50354 Hürth
Mail: guido.pe...@netcologne.de
Tel.: 02233 985 78 62
Mobil: 0177 59 61 256
----- Original Message -----
From: "Werner Laude" <newsgr...@wernerlaude.de>
To: "Mailingliste der Rails-Usergroup-Deutschland"
<rubyonrails-ug@headflash.com>
Sent: Sunday, January 03, 2010 11:44 AM
Subject: Re: [Rubyonrails-ug] Item aus array entfernen
Am 02.01.2010 um 17:58 schrieb Michael Schuerig:
Danke für die Antwort..
leider komme ich da noch nicht weiter. Nach einigem googeln....
<%=link_to('Artikel entfernen',delete_item_path(:id =>
cart_item.product_id))%> # z.b. id =10 ,also die reale produkt id
controller:
def delete_item
session[:cart].remove_product(Product.find(params[:id]))
end
cart model
def remove_product(product)
@items.delete_if { |item| item.product == product }
end
Das erscheint mir sehr schlüssig. Tut aber nicht was es soll.
Idee?
Gruß
Werner
On Saturday 02 January 2010, Werner Laude wrote:
def delete_product(product)
item = @items.find {|item| item.product == product}
item.delete
Aber irgendwie findet er den Teil des arrays nicht. Ist das delete
korrekt so?
Nein.
$ ri Array#delete
----------------------------------------------------------- Array#delete
array.delete(obj) -> obj or nil
array.delete(obj) { block } -> obj or nil
------------------------------------------------------------------------
Deletes items from _self_ that are equal to _obj_. If the item is
not found, returns +nil+. If the optional code block is given,
returns the result of _block_ if the item is not found.
a = [ "a", "b", "b", "b", "c" ]
a.delete("b") #=> "b"
a #=> ["a", "c"]
a.delete("z") #=> nil
a.delete("z") { "not found" } #=> "not found"
Michael
--
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/
_______________________________________________
rubyonrails-ug mailing list
rubyonrails-ug@headflash.com
http://mailman.headflash.com/listinfo/rubyonrails-ug
Werner Laude
no-s...@wernerlaude.de
_______________________________________________
rubyonrails-ug mailing list
rubyonrails-ug@headflash.com
http://mailman.headflash.com/listinfo/rubyonrails-ug
_______________________________________________
rubyonrails-ug mailing list
rubyonrails-ug@headflash.com
http://mailman.headflash.com/listinfo/rubyonrails-ug