1

私にはそのような問題があります。2つのアクションしか必要ないため、すべてのリソースをネストする必要はありません。

最初-1つのWebサイトに関連するすべてのレポートを表示します。

2番目-すべてのレポートを表示します。

このようにroutes.rbのコードを書き直すと:

resources :websites do
 member do
  match 'performance_reports' => 'performance_reports#index'
  match 'performance_reports/show' => 'performance_reports#show'
 end
end
 //rake routes
    performance_reports_website        /websites/:id/performance_reports(.:format)            
performance_reports#index

  performance_reports_show_website        /websites/:id/performance_reports/show(.:format) 
performance_reports#show

これが私の行動です:

 before_filter :load_website
  private

 def load_website
   @website = Website.find(params[:website_id])
 end

def index
   @performance_reports = @website.performance_reports
end

ビューからのコード:

    <%= link_to "Link",  performance_reports_website_path(website)) %>

しかし、私がそれを呼んでいるとき、私はエラーを受け取ります:

  Couldn't find Website without an ID
  rb:7:in `load_website'

私が間違っているのは何ですか?

4

1 に答える 1

1

コントローラでコードを次のように変更します

@website = Website.find(params[:id])
于 2012-09-05T10:10:34.570 に答える