Reputation: 29514
I am starting my learning process by first listing all the users.
First I had added an action in the controller as
def list_users
@users=User.find(:all)
end
And in the View users/list_users.html.erb
I have added the line
list_users.html.erb
:
<%= Time.now %>
<% @users.each do |user| %>
<%= user.firstname %>
<% end %>
And for routing I have added the routes as
map.list_users '/list_users', :controller => 'users', :action => 'list_users'
That's it .. when I run my app , it's showing me the error as
Development mode eh? Here is the error - #<ActionView::TemplateError:
ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each) on line #7 of app/views/users/list_users.html.erb:
Why so?
Solution:
I myself find that the controller action is under protected, that's why it showed me the error.
Upvotes: 0
Views: 220
Reputation: 16011
It seems that you didn't use the login
method in list_users.html.erb
, where did you used it?
But here is another error (maybe typo error only?)
<% @users.each do |user| %>
<%= user.firstname # not @user here! %>
<% end %>
Upvotes: 1