Rails 4.2 ActiveAdmin get admins email addr

三世轮回 提交于 2019-12-25 03:54:38

问题


This query always returns [nil]

AdminUser.all.collect{|a|a.email}

However these two queries just work fine.

AdminUser.all
AdminUser.all.collect{|a| a.current_sign_in_ip}

Why can't i get the email addresses?

Update

The email field itself is not nil .It is present in the AdminUser.all call and also this call retuns the correct email.

>>au=AdminUser.find(1)
>>au[:email] 
=>my@email.addr

Solution to the original problem

Through another question/problem i figured out i added attr_accessor on my :email field in my model/admin_user.rb i removed it and now also the AdminUser.all.collect{|a|a.email}

query works.


回答1:


You have a typo in first query:

AdminUsers.all.collect{|a|a.email} # should be AdminUser

The better way is to use pluck for such queries:

AdminUser.pluck(:email)


来源:https://stackoverflow.com/questions/33240876/rails-4-2-activeadmin-get-admins-email-addr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!