Rails 3.2.8 with authlogic returning "undefined method `each'
-
26-06-2021 - |
質問
I've been trying to set up authlogic with my Rails 3.2.8 server. I can get everything mostly working, but whenever I try to view my usernames I get this error.
undefined method `each' for nil:NilClass
I haven't seen any reason as to why this happens with rails apps. It works if I grab an old example, but not when I set it up with a recent version. Anyone know why this is happening? This is the specific code generated by rails that causes the issue, as far as I know it should be working.
<% @user_sessions.each do |user_session| %>
<tr>
<td><%= user_session.email %></td>
<td><%= user_session.password %></td>
<td><%= link_to 'Show', user_session %></td>
<td><%= link_to 'Edit', edit_user_session_path(user_session) %></td>
<td><%= link_to 'Destroy', user_session, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
Thanks in advance for any help!
Edit:
This is where @user_sessions is being set, in my config/routes.rb I have this
resources :users, :user_sessions
match 'login' => 'user_sessions#new', :as => :login
match 'logout' => 'user_sessions#destroy', :as => :logout
And my models/user.rb looks like this
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
acts_as_authentic
end
This is what my UsersController index looks like. Edit again:
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
end
And this is what my UserSessionController looks like:
def index
@user_sessions = UserSession.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @user_sessions }
end
end
Note: I had this commented out thinking it was an issue. If that isn't commented out it returns
undefined method `all' for UserSession:Class
解決