문제

I have such problem: I don't need to nest all resources, because I need only two action.

First - show all reports related with 1 website.

Second - show all reports.

When I rewrite code in routes.rb like this:

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

Here is my action:

 before_filter :load_website
  private

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

def index
   @performance_reports = @website.performance_reports
end

Code from view:

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

but when I'm calling it I get error:

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

What I'm doing wrong ?

도움이 되었습니까?

해결책

In controller change the code to

@website = Website.find(params[:id])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top