Rails Devise, using Onliner gem for list of online users -
i'm trying use onliner gem (https://github.com/kbokhonko/onliner) display list of online users. however, when try view page list should on "undefined method `each' nil:nilclass". note if change "user.online" "user.all" error message goes away , can view page it's not methods in wrong place or that, must doing wrong in implementation of gem. if familiar gem explain i'm doing wrong, great! i'm sure it's def online method not being set properly, i'm not sure how else write it.
users_controller.rb:
def online @users = user.online end
online.html.erb:
<table> <thead> <tr> <th>users online</th> </tr> </thead> <tbody> <% @users.each |user| %> <tr> <td><%= user.email %></td> <td><%= user.user_type %></td> <% if user_signed_in? && current_user.user_type == 'admin' %> <td><%= link_to 'destroy', user, method: :delete, data: { confirm: 'are sure wish delete user?' } %></td> <% end %> </tr> <% end %> </tbody> </table>
user.rb:
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :onliner
application_controller.rb:
before_filter { |c| current_user.track unless current_user.nil?}
you doing correct, looks there error in onliner
gem. user.online
returns nil
instead of empty array in case. suggest open issue in gem repo. or use other gem.
Comments
Post a Comment