简体   繁体   中英

Rails 4.2 ActiveAdmin get admins email addr

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM