0
我試圖爲視圖模板上的嵌套資源創建一個「編輯」鏈接。父資源是Project,子資源是Requirement。加載項目顯示模板時,我收到以下錯誤:NoMethodError for * _path
NoMethodError在項目#秀##類
未定義的方法`edit_requirement_path」:0x000001009e5bc8>:0x00000100f83760>
下面是代碼從需求部分(_requirement.html.erb
)。
<%= div_for requirement do %>
<h4>
<%= requirement.name %>
</h4>
<p><b>Type: </b><%= requirement.requirement_type.name %></p>
<p><b>Priority: </b><%= requirement.requirement_priority.name %></p>
<p><b>Detail: </b><%= simple_format requirement.detail %></p>
<p><b>Initiator: </b><%= requirement.initiator %></p>
<p><b>Approved: </b>
<% if requirement.approved? %>
Yes
<% else %>
No
<% end %>
</p>
<%= link_to 'Edit Requirement', edit_requirement_path(@requirement)%>
<% end %>
這是RequirementsController中Edit操作的代碼。
class RequirementsController < ApplicationController
...
def edit
@requirement = Requirement.find(params[:id])
end
...
這是Project展示模板(show.html.erb
)中的代碼。 ...
開始日期: <%= @ project.start_date%>
<p>
<b>End date:</b>
<%= @project.end_date %>
</p>
<p>
<b>Requirements Approved:</b>
<%= @project.requirements_approved %>%
</p>
<div id="requirements_display">
<h3>Project Requirements</h3>
<%= render @project.requirements %>
</div>
<div id="requirements_module">
<h3>Add New Requirement</h3>
<%= render :file => "requirements/new" %>
</div>
<%= link_to 'Edit', edit_project_path(@project) %> |
<%= link_to 'Back', projects_path %>
這是從routes.rb中文件的代碼。
Nexus::Application.routes.draw do
resources :requirement_priorities
resources :project_services
root :to => "projects#index"
resources :projects do
resources :requirements
end
感謝您的回覆。如果我刪除實例符號,該錯誤會持續存在。然而,對班級的提及確實會改變。使用@ throws:「#<#:0x000001023cb4c0>」,而沒有@拋出「#<#:0x00000100a82f18」。 –
justinraczak
2012-03-21 17:11:57