在Rails 5,为什么我根据其中一个字段搜索模型时得到未定义的find_by方法?
In Rails 5, why do I get undefined find_by method when I search for a model based on one of its fields?
我正在使用 Rails 5. 我想搜索基于 user_id 字段的模型。我的 table 看起来像这样
cindex=# \d user_notifications;
Table "public.user_notifications"
Column | Type | Modifiers
--------------------+---------+-----------------------------------------------------------------
id | integer | not null default nextval('user_notifications_id_seq'::regclass)
user_id | integer |
crypto_currency_id | integer |
price | integer | not null
buy
| boolean | not null
但是当我尝试查找这样的模型时
@user_notification = UserNotification.find_by_user(current_user)
我收到错误
undefined method `find_by_user' for UserNotification:Class
查找我的字段的简单(Rails)方法是什么?
我正在使用 Rails 5. 我想搜索基于 user_id 字段的模型。我的 table 看起来像这样
cindex=# \d user_notifications;
Table "public.user_notifications"
Column | Type | Modifiers
--------------------+---------+-----------------------------------------------------------------
id | integer | not null default nextval('user_notifications_id_seq'::regclass)
user_id | integer |
crypto_currency_id | integer |
price | integer | not null
buy
| boolean | not null
但是当我尝试查找这样的模型时
@user_notification = UserNotification.find_by_user(current_user)
我收到错误
undefined method `find_by_user' for UserNotification:Class
查找我的字段的简单(Rails)方法是什么?