On Sat, Feb 19, 2011 at 4:47 PM, Juan manuel V. <[email protected]> wrote:
> @elements = Post.find(:all)
> @elements.each do |el|
> if el.name=="test"
> # remove el from @elements
> end
> end
First, it would be more readable for you or another maintainer
down the road to write this as
@posts = Post.all
@posts.each do |post|
> How can i achieve this? i was trying to do
> el.delete but that is going to delete the element from the database
> and i just want the element to be removed from current listing.
@posts is an Array; look at the rdoc for methods available.
And finally, you could replace the .each loop with one line:
@posts.delete( Post.find_by_name("test") )
HTH!
--
Hassan Schroeder ------------------------ [email protected]
twitter: @hassan
--
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.