Reputation: 129
I added a Session controller to my application for user sign-in / sign-out, using
rails g controller Session new create destroy
then add the following lines to my route file:
resources :sessions, :only => [:new, :create, :destroy]
match '/signup', :to => 'users#new'
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
when I do rake routes
in the console, the routes do show up, but when I launch the app in the browser, I got this error:
uninitialized constant SessionsController
Thanks in advance!
Upvotes: 2
Views: 4318
Reputation: 377
I was running into this today, and found I had to do three things, 1) use resource (not resources); 2) supply the controller manually, and 3) manually set the url in form_for tags using the resource (may not apply for your case)...
# routes.rb
resource :session, :only => [:new, :create, :destroy], :controller => 'session'
#.../new.html.erb
<% form_for @session, :url => session_path do |f| %>
Specifying the controller matters if, like me, your controller name, file names, etc, are all singular.
This is apparently related to a bug in rails
Upvotes: 3
Reputation: 124449
You created a Session
controller, not a Sessions
controller. Since it's singular, you want a singular route:
resource :session, :only => [:new, :create, :destroy]
Upvotes: 6