我有两个数组:
@all_genres = [#<Genre id: 1, name: "Action", created_at: "2013-03-01 07:44:51", updated_at: "2013-03-01 07:44:51">,
#<Genre id: 2, name: "Adventure", created_at: "2013-03-01 07:44:51", updated_at: "2013-03-01 07:44:51">,
#<Genre id: 3, name: "Animation", created_at: "2013-03-01 07:44:51", updated_at: "2013-03-01 07:44:51">]
@genres = ["Action", "Animation"]
我试图找到与表格相比的Genre.id
from 。例如我的结果应该是:@genres
@all_genres
@genre_ids = [1, 3]
我试过这个:
@all_genres.each do |g|
if g.name.include?((@genres.each {|g| g}).to_s)
@genre_ids << g.id
end
end
我在控制台中尝试了这个,它似乎可以工作,但是当我将它放入我的应用程序时它返回:
@genre_ids = []