如何使用named_scope将记录限制为非空白记录?
我构建了一个 Ruby on Rails 应用程序 (2.3.9),它允许用户跟踪锻炼情况。我尝试仅从 Workout
表中返回在 video_link
列中具有值的记录。 (workout.video_link
是一个字符串,包含一个网址)。
我之前使用 named_scope
来限制记录,但仅限于整数列,我不知道如何使用字符串来执行此操作,因为 IS NOT NULL
显然不会'不在这里工作。
我如何在 workout.rb
中编写范围来完成这样的事情?
I have built a Ruby on Rails application (2.3.9) which allows users to track workouts. I am trying to only return records from my Workout
table which have a value in the video_link
column. (workout.video_link
is a string and contains a web address).
I have used a named_scope
to limit records before but only on columns which were integers, I am not sure how to do this with a string as the IS NOT NULL
obviously won't work here.
How would I write the scope in workout.rb
to do such a thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将条件指定为字符串来检查
IS NOT NULL
:You can specify conditions as a string to check
IS NOT NULL
:改进 Pan Thomakos 的例子:
Improving on Pan Thomakos' example: