restful authentication

Subscribe to restful authentication 4 post(s), 3 voice(s)

 
Avatar beta 7 post(s)

I am running rails 1.2.3 and took the entire Restful authentication plugin from the source file, however when i tried to run my app for the first time as show on page 111 i got errors:


ActionView::TemplateError (session_url failed to generate from {:controller=>"sessions", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route.  content_url has the following required parameters: ["session", :id] - are they all satisifed?) on line #1 of app/views/sessions/new.rhtml:

Allthough my code was the same as in the source file and in the book i tried something that was written in the plugin readme and changed my roots.rb file from this:


ActionController::Routing::Routes.draw do |map| 
map.resources :exercises 
map.home '', :controller => 'sessions', :action => 'new' 
map.resources :users, :sessions 
map.signup '/signup', :controller => 'users', :action => 'new' 
map.login  '/login', :controller => 'sessions', :action => 'new' 
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
end 

as was in the book… to this:


ActionController::Routing::Routes.draw do |map|
map.resources :exercises
map.home '', :controller => 'sessions', :action => 'new'
map.resources :users
map.resource :session, :controller => 'sessions'
map.signup '/signup', :controller => 'users', :action => 'new' 
map.login  '/login', :controller => 'sessions', :action => 'new' 
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
end

And now it works without problem! Has anyone else had this experience, is it just a result of things getting mixed up a bit because of using previous versions?

UPDATE: I have seen on page 113 that the sessions_controller.rb is refferred to as session_controller.rb, if i generate the restful auth code with ‘session’ instead of then ‘sessions’ as the second parameter then I can leave the routes.rb code as is in the book and it works fine.

 
Avatar EldonAlameda Administrator 216 post(s)

Yeah I’ve never been a big fan of the decision to allow singular resources in Rails.

 
Avatar fengfan 2 post(s)

Yes, I copy the REST authentication plugin sources in the Eldon’s project to my project of same name it,and so edit my router.rb,

ActionController::Routing::Routes.draw do |map|
map.resources :exercises
map.home ’’, :controller => ‘sessions’, :action => ‘new’
map.resources :users
map.resource :session, :controller => ‘sessions’
map.signup ’/signup’, :controller => ‘users’, :action => ‘new’
map.login ’/login’, :controller => ‘sessions’, :action => ‘new’
map.logout ’/logout’, :controller => ‘sessions’, :action => ‘destroy’
end

now My project is work OK!

Thanks Eldon and beta!

 
Avatar EldonAlameda Administrator 216 post(s)

Glad to hear that you got past that issue and sorry for the confusion.

I learned my lesson about plugins that keep changing after the book is written with this book. So in my new book – I made sure to fork my own version of each plugin on GitHub for the readers to use.