Simple routing problem

I've got the following in config\routes.rb:
map.resources :users

In app\views\shared\_menu.erb, I've got:
Please sign in <%= link_to
"here", :controller=>"user", :action=>"sign_in" -%>

In app\controllers\users_controller.rb
  def sign_in
  end

When I run the application, I crash with:
Routing Error
No route matches "/user/sign_in" with {:method=>:get}

I presume I should add "def sign_in; [snip]; end" somewhere in:
app\views\users

But where, so as to satisfy the Rails routing scheme?
Is sufficient information provided above to answer this question?
I'm running Rails 2.3.5

Thanks in Advance,
Richard

map.resources creates routes for the typical CRUD operations. Since you are adding an additional operation, you could revise your mapping to this:

map.resources :users, :collection => {:sign_in => :get}

This creates awkward route names & feels ugly as you are mucking with a resource controller's routes. It's probably better to do:

map.sign_in "/sign_in", :controller => "users", :action => "sign_in"

However, as logging in is really a session issue, rather than a user concern, it would be even better to do something like this:

map.sign_in "/sign_in", :controller => "sessions", :action => "new"

Then move your sign_in method from users_controller to sessions_controller

You will want a file like /path_to_controller_views/sign_in.html.erb to handle it (assuming you are using erb). Replace path_to_controller_views with either /app/views/users or /app/views/sessions as appropriate.

Niels

Hey Niels,

Thank you for excellent guidance. I read about routing but it's taking
me a long time to actually internalize this stuff. Your analysis
gives me hope!

Best wishes,
Richard

Hey Niels,

Thank you for excellent guidance. I read about routing but it's taking
me a long time to actually internalize this stuff. Your analysis
gives me hope!

Have a look at the Rails Guide on routing. As always don't just read
it, play with a test app and try variants of the examples in the
guide. That helps the ideas to sink in, at least it helps for me.

Colin

Hi Colin,

Have a look at the Rails Guide on routing.

Good idea. I'm still stuck on that.issue. Thanks.

Best wishes,
Richard