views:

26

answers:

1

I just issued a [ script/generate scaffold User ] command to generate my files. All the CRUD pages work well so that's good and now I'm trying to create more pages. I create a method in the user_controller.rb file as follows:

def login

#blahblah

end

Then created app/views/users/login.html.erb for the view. When I tried accessing it through the browser [http://localhost:3000/users/login] it gives out the error:

ActiveRecord::RecordNotFound (Couldn't find User with ID=login): app/controllers/users_controller.rb:16:in `show'

I'm interpreting it as using the action show and it doesn't recognize login as an action. Am I missing some configuration for this action to work? I'm quite new to Rails so I might be missing something trivial. Thanks!

UPDATE I tried using [script/generate controller User] then created action methods in the controller and it's corresponding views. It seems to work as predicted. What makes the difference between the two and what causes the creation of additional action methods when using script/generate scaffold not available?

A: 

You need to open your routes file and add a collection mapping to the users route. In your case, the line might read map.resources :users, :collection => { :login => :get }

Check out http://guides.rubyonrails.org/routing.html for more info on Rails routes

William
great! that works well. However, why is it that , if I use [script/generate controller user] then add methods in the controller and their corresponding views, they work without setting the mapping? What makes the script/generate scaffold different? Thanks!
Paul
Wait ... I think I got the hang of it now. Thanks!
Paul