我试图使用activerecord查询获取特定行内的行的值。我已经完成了所有的rails文档,但似乎无法找到出路。
因此,我所谈论的表格包含这些行:
id,flaggable_type,flaggable_id,flagger_type,reason,created_at, updated_at和flag_processed_at
我试图通过以下方式获取flag_processed_at的值:
<% flagged_unprocessed = current_message_flaggings.find(resource.id).flag_processed_at%>
我有这个错误
11:37:18 web.1 | ActionView::Template::Error (undefined method `flag_processed_at' for #<Enumerator: [237]:find(238)>):
11:37:18 web.1 | 1: <% flagged = current_message_flaggings.include?(resource.id) %>
11:37:18 web.1 | 2: <% flagged_unprocessed = current_message_flaggings.find(resource.id).flag_processed_at%>
11:37:18 web.1 | 3:
11:37:18 web.1 | 4: <% if resource.archived_by?(current_user) %>
11:37:18 web.1 | 5: <%= render partial: 'app/messages/message/archived', locals: { message: resource } %>
11:37:18 web.1 | app/views/app/messages/_message.html.erb:2:in `_app_views_app_messages__message_html_erb__2724530553012578480_69900141016240'
11:37:18 web.1 | app/views/app/conversations/show.html.erb:20:in `block in _app_views_app_conversations_show_html_erb__3548922752939129799_69900161876900'
11:37:18 web.1 | app/views/app/conversations/show.html.erb:17:in `_app_views_app_conversations_show_html_erb__3548922752939129799_69900161876900'
11:37:18 web.1 |
11:37:18 web.1 |
答案 0 :(得分:2)
Rails会返回枚举器类:
YourModel.where(id: xxx).to_a.find(xxx)
返回枚举器
确保您的 current_message_flaggings var不是数组