Ok so I was having this problem before and thought Id start again from scratch. Here is an example of my index.html.erb file <% for user in @users %> <tr> <td><%= h user.SurName %></td> <td><%= h user.ForeName %></td> <td><%= link_to ''Show'', user %></td> <td><%= link_to ''Edit'', edit_user_path(user) %></td> <td><%= link_to ''Destroy'', user, :confirm => ''Are you sure?'', :method => :delete %></td> </tr> <% end %> <%= link_to ''New user'', new_user_path %> The links rendered for show edit and destroy are all wrong they basically leave out the ID of the user and so don''t work as links EG: "Show" links to /users/ rather than say /users/10 for example, and "Edit" links to /users//edit rather than /users/10/edit I find if I edit my code to be more of the form <td><%= link_to ''Show'', :action => ''show'', :id => user.ID %></td> <td><%= link_to ''Edit'', edit_user_path(user.ID) %></td> Then the paths are fine, but every tutorial I''ve read seems to imply that this shouldn''t be necessary. Am I doing something obvious wrong? My routes.rb file is very standard ActionController::Routing::Routes.draw do |map| map.resources :users map.root :controller => "users" map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2008-May-27 12:23 UTC
Re: Newbie: Wierd ID not routing by default problem.
this should work: <td><%= link_to ''Show'', user_path(user.id) %></td> <td><%= link_to ''Edit'', edit_user_path(user.id) %></td> <td><%= link_to ''Destroy'', user_path(user.id), :confirm => ''Are you sure?'', :method => :delete %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> this should work: > > <td><%= link_to ''Show'', user_path(user.id) %></td> > <td><%= link_to ''Edit'', edit_user_path(user.id) %></td> > <td><%= link_to ''Destroy'', user_path(user.id), :confirm => ''Are you > sure?'', > :method => :delete %>Ok cool, but does this mean that I''ve just been reading bad tutorials? Or is it a configuration issue? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---