-1

私は 3 つのテーブルを持っています。1 つは病気を含み、もう 1 つは症状を含み、もう 1 つは多対多の disease_symptom テーブルです。病気のページから、この特定の病気の症状を含む新しいページにユーザーを誘導するハイパーリンクを追加したいと考えています (アルファベット順にソートされています)。

私は ROR を初めて使用するので、この新しいページをプロジェクト ツリーのどこに配置すればよいか、またルートを追加する方法がよくわかりません。

「Pages」というディレクトリを追加し、その下に新しいファイル「symptomsForIllness.html.erb」を配置しました。さらに、病気/番組の html にハイパーリンクを追加しました。

<%= link_to 'Symptoms',symptomsForIllness_path(@illness) %>

また、routes.rb に次のルートを追加しようとしました。

match '/symptomsForIllness_path' => 'Pages#symptomsForIllness'

次のエラーが表示されます。

ActionView::Template::Error (未定義のメソッドsymptomsForIllness_path' for #<#<Class:0x3f1fbc0>:0x32d0060>): 10: <%= link_to 'Back', illnesses_path %> 11: <br /> 12: <%= link_to 'symptoms',symptomsForIllness_path(@illness) %> app/views/illnesses/show.html.erb:13:in_app_views_illnesses_show_html_erb___154118681_26683248' app/controllers/illnesses_controller.rb:19:'show' 内

このようなファイル (多対多の関係を表すファイル) をディレクトリ ツリーのどこに配置するか、およびこのエラーを回避する方法を教えてください。

ありがとう、リー

4

1 に答える 1

1
#in routes.rb
resources :symptoms :only => [:index] do
  get 'illnesses', :on => :member
end

resources :illnesses :only => [:index] do
  get 'symptoms', :on => :member
end   

ビューpath_helpersで

illnesses_symptom_path(@symptom) #symptoms controller, illnesses action

symptoms_illness_path(@symptom) #illnesses controller, symptoms action
于 2012-05-26T17:26:13.007 に答える