Reputation: 7279
I have a method like this :
class ProfilesController < ApplicationController
before_filter :authenticate_user!
current_user
def index
@users = User.all
end
...
end
and my route is
match 'profile', :controller => 'profiles', :action => 'index'
but when I access http://127.0.0.1:8080/profile
I get:
NoMethodError
inProfiles#index
undefined methodeach
fornil:NilClass
Upvotes: 0
Views: 2090
Reputation: 7279
Worked. I just removed the line current_user
from my ProfilesController
@Jesper do this have something with the filter you said?
Upvotes: 0
Reputation: 43153
This means User.all
is returning nil. You need to check if there are any users before calling each on them. If you changed your view to look like this it would not raise the error.
<% if @users %>
<% @users.each do |user| %>
...
<% end %>
<% end %>
Upvotes: 2