2013-12-17 48 views
0

这可能是一个非常愚蠢的问题。我对Ruby很新,因此不知道我在做什么。 我在application.html.erb中设置了一个布局。我的导航链接之一就是链接到简历的默认显示页面。我应该可能将其设置为索引而不是显示。但是当我尝试时,事情变得更加混乱。Ruby on Rails UrlGenerationError

随着我目前拥有的代码,我得到的错误是

Showing thisSectionOfUrlTakenOut/app/views/layouts/application.html.erb 
where line #22 raised: 

No route matches {:controller=>"resume", :action=>"show"} missing required keys: 
[:id] 


Extracted source (around line #22): 

19 <ul> 
20 <li><%= link_to "Home", welcome_index_path %></li> 
21 <li><%= link_to "Projects", projects_path %></li> 
22 <li><%= link_to "Resume", resume_path, method => show %></li> 
23 <li><%= link_to "Blog", posts_path %></li> 
24 </ul> 
25 </nav> 

原样,我application.html.erb看起来是这样的。

<!DOCTYPE html> 
<html> 
<head> 
     <title>Portfolio</title> 
     <%= stylesheet_link_tag "application", media: "all", 
"data-turbolinks-track" => true %> 
     <%= javascript_include_tag "application", 
"data-turbolinks-track" => true %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 
<header> 

    <% if current_user %> 
     <h1>Welcome</h1> 
    <%else%> 
     <h1> Portfolio</h1> 
    <%end%> 

    <nav> 
    <ul> 
     <li><%= link_to "Home", welcome_index_path %></li> 
     <li><%= link_to "Projects", projects_path %></li> 
     <li><%= link_to "Resume", resume_path, method => show %></li> 
     <li><%= link_to "Blog", posts_path %></li> 
    </ul> 
    </nav> 

</header> 

<%= yield %> 

<footer> 
    <% if !current_user %> 
     <%= link_to "Login", admin_console_index_path%> 
    <% else %> 
     <%= link_to "Logout", destroy_user_session_path, :method => :delete%> 
    <%end%> 
</footer> 

</body> 
</html> 

的routes.rb中看起来像

Portfolio::Application.routes.draw do 

    devise_for :users 

    resources :posts do 
    resources :comments 
    end 

    resources :projects 

    resources :resume 

    resources :admin_console 

    resources :welcome 

    root 'welcome#index' 
end 

而且resume_controller.rb看起来像

class ResumeController < ApplicationController 
    def show 
    end 
end 

如果有帮助,一些问题开始时,我开始使用设计。但从那以后,我认为其他的错误让事情变得更糟。我会非常感谢任何帮助。如果你能解释给我,那会更好

+0

你会有多个简历保存在分贝,或者这是一个个人网站,你只会显示自己的? – jstim

+0

你是通过网站上的表单创建简历还是通过手工通过html? –

+0

资源需要一个id来显示特定的简历@jstim askes你会有更多的1,或者你只是想/继续显示*你的*简历?如果前者,你需要传递一个简历对象(或一个id到resume_path) – Doon

回答

0

问题出在你的路线上。你正在定义resources :resume这意味着有许多简历,因此当你想链接到简历,你必须知道它的ID。

你应该做的却是:

get '/resume' => 'resume#show' 

同时删除在你的简历链接method => show选项。这是不需要的,一旦你修复路线,可能会导致错误。

+0

非常感谢你! –