Reputation: 155
In my "main" controller I am trying to query the article table to find all the articles where the link (this is a field with article url) contains a specific domain. I can't for the life of me figure it out.
It tried the below but get the following error:
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "link"
This is what I have in my controller:
@featured = Article.where("link.includes? 'example.com'")
Any help would be appriciated.
Upvotes: 0
Views: 251
Reputation: 135
The string parameter of where
method is for your database engine as part of SQL, not for Ruby interpreter.
So you should write it like:
@featured = Article.where('link LIKE ?', '%example.com%')
Here the LIKE
is a SQL keyword.
See Rails 4 LIKE query - ActiveRecord adds quotes.
Upvotes: 1