Hi, I have spent the last couple of hours Googling and trying any thing that i think will work but i haven''t any luck. :( Here is an outline of what I am trying to do. I want to show a use there info by going to "http://localhost:3000/ users/5c6e957b523f931fdda3e9922b680c2d868cf44b" (random token) This is what I have in the routes file and the controller. # routes Reg::Application.routes.draw do resources :users root :to => "users#new" match "/users/:token" => "users#show" end # controller def show @user = User.find(params[:token]) end At the moment it is giving me this error. Started GET "/users/5c6e957b523f931fdda3e9922b680c2d868cf44b" for 127.0.0.1 at 2011-01-30 09:54:23 +1100 Processing by UsersController#show as HTML Parameters: {"id"=>"5c6e957b523f931fdda3e9922b680c2d868cf44b"} Completed in 10ms ActiveRecord::RecordNotFound (Couldn''t find User without an ID): app/controllers/users_controller.rb:7:in `show'' This is one of my first rails apps so I don''t know exactly what is causing it - I guess that it will be a simple thing :) Thanks for you help. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello Can i have your view source code(I mean view in mvc). -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello Instead of this def show @user = User.find(params[:token]) end Try def show @user=User.find_by_id(params[:token]) end If id is the column in development table if you want to find details by username you can use @user=User.find_by_username(params[:token]) In general @user=User.fin_by_column_name(value) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The problem is in the routes. The first match found will be what that url is routed to, so when you declared resources :users, it defines / users/:id to match users#show. Try this: Reg::Application.routes.draw do resources :users, :except => [:show] root :to => "users#new" match "/users/:token" => "users#show", :via => :get end On Jan 29, 5:56 pm, camgill <gilroy.came...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have spent the last couple of hours Googling and trying any thing > that i think will work but i haven''t any luck. :( > > Here is an outline of what I am trying to do. > > I want to show a use there info by going to "http://localhost:3000/ > users/5c6e957b523f931fdda3e9922b680c2d868cf44b" (random token) > > This is what I have in the routes file and the controller. > > # routes > > Reg::Application.routes.draw do > resources :users > > root :to => "users#new" > > match "/users/:token" => "users#show" > end > > # controller > > def show > @user = User.find(params[:token]) > end > > At the moment it is giving me this error. > > Started GET "/users/5c6e957b523f931fdda3e9922b680c2d868cf44b" for > 127.0.0.1 at 2011-01-30 09:54:23 +1100 > Processing by UsersController#show as HTML > Parameters: {"id"=>"5c6e957b523f931fdda3e9922b680c2d868cf44b"} > Completed in 10ms > > ActiveRecord::RecordNotFound (Couldn''t find User without an ID): > app/controllers/users_controller.rb:7:in `show'' > > This is one of my first rails apps so I don''t know exactly what is > causing it - I guess that it will be a simple thing :) > > Thanks for you help.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.