Re: [Rails] Check if array content an object using include
On Sat, Jan 5, 2013 at 1:49 PM, Jean <josorioe@gmail.com> wrote:
> I have the following array on my rails console:
>
> u.favorites
>
> [#<Favorite id: 20, candidate_id: 6, ...>, #<Favorite id: 21, candidate_id:
> 7,..">, #<Favorite id: 22, candidate_id: 8, ...">, #<Favorite id: 23,
> candidate_id: 9, ...">, #<Favorite id: 24, candidate_id: 10, ...">]
>
> As you can see, I have candidate_id:6, candidate_id:7, candidate_id:8,
> candidate_id:9, candidate_id:10. But if I try this:
>
> u.favorites.include?(:candidate_id => 5) o canidate 6, 7, 8, 9 or 10 I get
> false.
u.favorites.keep_if { |f| f.canidate_id == 5 }
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home