mysql - all方法未定义时如何查询所有记录?

标签 mysql sql ruby-on-rails postgresql youtube-api

我正在尝试搜索给定 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/

相关文章:

sql - 一条Sql语句的帮助

mysql - 选择表 A 中与表 B 中的一组项目相连接的行

php - 我在我的 php 脚本中找不到错误

mysql - Ubuntu - 从 mysql 中的命令提示符重新启动 mysql

php - 使用准备好的 PDO 语句

ruby-on-rails - 使用 Devise/Rails 4/Minitest 运行 Controller 测试时无法登录

php - (插入+重复键更新)+更新?

mysql - 不同的值作为另一列中的字符串

mysql - rails : how to find all users older then n minutes ago where n is stored in joined group

javascript - Turbolinks 不起作用(页面加载两次)