Erstellen einer grundlegenden Telefonbuch App und einige Änderungen vorgenommen, während die Beziehungen has_many und gehört_to. Ich muss etwas kaputt gemacht haben, weil ich keine Ahnung habe, warum ich diesen Fehler bekomme. Wenn ich meine Root-Zugriff, erhalte ich die folgende ->Rails URL Generierungsfehler, aber Route existiert
ActionController::UrlGenerationError in ContactsController#index
No route matches {:action=>"show", :controller=>"contacts"} missing required keys: [:id]
Der Fehler Fehler in den Zeilen zeigt:
app/views/contacts/index.html.erb:10:in `block in _app_views_contacts_index_html_erb___2771775118522806317_70170309989460'
app/views/contacts/index.html.erb:7:in `_app_views_contacts_index_html_erb___2771775118522806317_70170309989460'
Dies ist meine Kontakte/index.html.erb
<p id="notice"><%= notice %></p>
<% if user_signed_in? %>
<h1>Listing Contacts</h1>
<% @contacts = current_user.contacts %>
<% @contacts.each do |contact| %>
<div class="link row clearfix">
<h2>
<%= link_to contact.name, contact_path %>
</h2>
</div>
<% end %>
<% end %>
<%= link_to "New Contact", new_contact_path %>
<% else %>
<h5> Welcome. Make an account or sign in above! </h5>
<% end %>
Dies ist meine Konfig/Routen
Rails.application.routes.draw do
resources :controllers
devise_for :users
resources :contacts so
resources :numbers
end
end
end
Dies ist meine Kontakte/show.html.erb
<div class="page-header">
<h1><a href="<%= @contact.name %>"><%= @contact.name %></a><br> </h1>
</div>
<p>
<strong>Name:</strong>
<%= @contact.name %>
</p>
<p>
<strong>Email:</strong>
<%= @contact.email %>
</p>
<br>
<%= link_to 'Edit', edit_contact_path(@contact) %> |
<%= link_to 'Back', contacts_path %>
Der Ausgang meiner Rake Routen:
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
contact GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
Wie Sie sehen können, habe ich einen Weg für Kontakte # show haben, so dass nicht der Fehler ist. Ich weiß nicht, was es sein könnte. Irgendwelche Ideen?
was ist die Route, die Sie genau verwenden? Es kann hilfreich sein, den Code auch im Contacts-Controller zu veröffentlichen. –
Die root-Route lautet contacts # index. – Sunny
Entschuldigung, ich meine, was ist die URL, die Sie genau verwenden, wie localhost: 3000/Kontakte /? usw. –