Page rendered is empty even though view and controller exist.
-
22-09-2019 - |
Question
I'm following this article(http://asciicasts.com/episodes/160-authlogic), I'm not using nifty generator tho.
I've done the User model and localhost:3000/users/new
page works fine.
But when I try to open localhost:3000/login
, the page is just empty. The source is empty too.
I've just copied the source from the site.
routes.rb
map.login 'login', :controller => 'user_sessions', :action => 'new'
map.logout 'logout', :controller => 'user_sessions', :action => 'destroy'
map.resources :user_sessions
map.resources :users
user_sessions_controller.rb
class UserSessionsController < ApplicationController
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Successfully logged in."
redirect_to root_url
else
render :action => 'new'
end
end
def destroy
@user_session = UserSession.find
@user_session.destroy
flash[:notice] = "Successfully logged out."
redirect_to root_url
end
end
/views/user_sessions/new.html.erb
<% form_for @user_session do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :username %><br />
<%= f.text_field :username %>
</p>
<p>
<%= f.label :password %><br />
<%= f.password_field :password %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
The code is just same as the site.
The server console shows that the views are being rendered:
Completed 200 OK in 149ms (Views: 145.5ms | ActiveRecord: 3.2ms)
Why is the login form not displayed at all?
Update
After added new action 'index' into user_sessions controller(also plus index.html.erb), if I open localhost:3000/user_sessions/index
shows me below message.
Unknown action No action responded to show. Actions: create, destroy, index, and new
And, this is WEBrick output
Processing UserSessionsController#show (for 127.0.0.1 at 2010-01-22 12:47:10) [GET]
Parameters: {"id"=>"index"}
ActionController::UnknownAction (No action responded to show. Actions: create, destroy, index, and new):
Solution
I've found the reason.
There was nothing in Views/layouts/application.html.erb, the file is exist, tho.
OTHER TIPS
/views/new.html.erb
should be located at views/user_sessions/new.html.erb