我正在尝试搜索给定 YouTube 视频的评论,以查看它是否包含特定字符串。
我的 api 调用使用 Yt gem工作得很好。但是,我很挣扎,因为 .all
和某些 SQL 查询无法正常工作,因为响应集合似乎是延迟加载的。
问题 -- 如何查询 CommentThreads 集合以查看其哪些项目包含特定字符串(如“parts”)?
下面是我尝试运行的几个表达式的控制台输出,包括 LIKE 查询:
@video_comments
=> #<Yt::Collections::CommentThreads:0x007fe626f70120>
@video_comments.all
=> NoMethodError: undefined method `all' for #<Yt::Collections::CommentThreads:0x007fe626f70120>
@video_comments.first.text_display
=> "Links for the parts in the description! <br /><br />What color do you want?"
@video_comments.first.text_display.include? "parts"
=> true
@video_comments.where('text_display LIKE ?', "%parts%").first
=> ArgumentError: wrong number of arguments (given 2, expected 0..1)
from /Users/macbook/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/yt-0.28.5/lib/yt/collections/base.rb:37:in `where'
Rails 5.0.1 + ruby 2.3.0p0 + psql (PostgreSQL) 9.6.1
编辑:实际的@video_comments
响应http://imgur.com/bjkXWfO
最佳答案
.all
适用于模型,例如如果您有一个 VideoComments 模型,则 VideoComments.all
将返回所有评论。
您的最后一个查询应该可以工作,您只是有一个语法错误,请尝试
@video_comments.where('text_display iLIKE = ?', "%parts%").first
关于mysql - all方法未定义时如何查询所有记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43712546/