Monday, March 2, 2009

NAMEERROR IN SESSIONSCONTROLLER WHILE USING RESTful_authentication

NAMEERROR IN SESSIONSCONTROLLER#CREATE
uninitialized constant SessionsController
RAILS_ROOT: C:/rails/bookmarks
Application Trace | Framework Trace | Full Trace
REQUEST
Parameters:
{"commit"=>"Log in",
"authenticity_token"=>"0c0f07222da8ed58d8c6ebcafb9bf32f0bc84143",
"login"=>"anthony",
"password"=>"mysupersecretpassword"}
Uh oh! what went wrong? It looks like Rails is looking for a controller called SessionsController. But we generated one
named SessionController. Why is this happening? Take a look in the views/session/new.html.erb file.
<% form_tag session_path do -%>


<%= text_field_tag 'login' %>



<%= password_field_tag 'password' %>


<%= submit_tag 'Log in' %>


<% end -%>
The form_tag target is session_path. session_path is created for us by magic because of its mapping in routes.rb.
map.resource :session
When mapping a resource like this Rails looks for the controller with the pluralized name of the resource name by default,
which means session_path is getting SessionsController. We can change the behavior by explicitly setting the controller for the resource.

map.resource :session, :controller => :session
Try to log in again and you will be authenticated! Of course it may just be easier to remember to use the pluralized name of whatever controller you want to use for managing sessions.

No comments:

Post a Comment