I get an error with my routes when I try to override to_param in my user model to use the email address as an identifier. It seems to be trying to map the entire object for the identifier when it tries to map the route. Can someone help me figure out what I am missing?
Here's the error:
No route matches {:controller=>"users", :action=>"show", :id=>
This is how I set up the code.
/ user.rb models:
attr_accessible :email def to_param email end
Controllers / users_controller.rb:
before_filter :get_user, :only=>[:show,:update,:edit,:destroy] ... def get_user @user = User.find_by_email params[:id] end
config / routes.rb
resources :users
And here is the conclusion from the rake routes:
user GET /users(.:format) {:controller=>"users", :action=>"index"} POST /users(.:format) {:controller=>"users", :action=>"create"} new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"} edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"} user GET /users/:id(.:format) {:controller=>"users", :action=>"show"} PUT /users/:id(.:format) {:controller=>"users", :action=>"update"} DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
Bee
source share