2016-07-07 6 views
1

基本的な電話帳アプリケーションを作成し、has_manyとbelongs_toの関係を把握しながらいくつかの変更を行いました。なぜ私はこのエラーが出ているのかわからないので、何かを壊したに違いない。私は私のルートにアクセスすると、私は次の取得 - >Rails URL生成エラーですがルートが存在します

ActionController::UrlGenerationError in ContactsController#index 
No route matches {:action=>"show", :controller=>"contacts"} missing required keys: [:id] 

エラーが行の間違いを示しています

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' 

これは私の連絡先/ 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 %> 

これは自分の設定/ルートです

Rails.application.routes.draw do 
    resources :controllers 
    devise_for :users 

    resources :contacts so 
    resources :numbers 
    end 
end 
end 

あなたが見ることができるようにそれは間違いではありませんので、私は連絡先番号のショーのためのルートを持っている

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 

:私の連絡先/ 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 %> 

私のすくいルートの出力されます。私はそれが何であるかについては不明です。何か案は?

+0

あなたは正確に使用しているルートは何ですが?連絡先コントローラにコードを投稿するのに役立つかもしれません。 –

+0

ルートルートはcontacts#indexです。 – Sunny

+0

申し訳ありませんが、localhost:3000/contacts /のように、あなたが使っているURLは何ですか? –

答えて

0

contact_path:idが欠落しているようです。 contacts/index.html.erb

、この変更:これに

<%= link_to contact.name, contact_path %> 

<%= link_to contact.name, contact_path(contact.id) %> 
+1

なぜ早く動作していたのですが、今入力したIDが必要ですか?ウェブサイトが私にできるようになるとすぐにあなたの答えを正しいものとしてマークします。 – Sunny

+0

'config/routes.rb'で何か変更した場合を除き、私はなぜか分かりません。 * git *の使用を検討し、定期的にコードをコミットすると、 'git diff'を使ってコミットを比較することができます:https://git-scm.com/docs/git-diff – SoAwesomeMan

関連する問題