2012-03-21 6 views
0

ビューテンプレートでネストされたリソースの「編集」リンクを作成しようとしています。親リソースはProjectで、子リソースはRequirementです。プロジェクトショーテンプレートをロードするとき、私は次のエラーを取得する:* _pathのNoMethodError

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の編集アクションのコードです。

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 

答えて

0

<%= link_to 'Edit Requirement', edit_requirement_path(@requirement)%> 

インスタンス変数@requirementの代わりに、ローカル変数requirement(無@記号)を渡しています。

@を削除すると機能しますか?

+0

返信いただきありがとうございます。インスタンスシンボルを削除すると、エラーは持続します。しかし、クラスへの参照は変更されます。 @ throws: "#<#:0x00000100a82f18"を使わずに、@ throws: "#<#Class:0x000001009ae150>:0x000001023cb4c0" – justinraczak