1

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 ?

MID
  • 1,815
  • 4
  • 29
  • 40

1 Answers1

1

In controller change the code to

@website = Website.find(params[:id])
abhas
  • 5,193
  • 1
  • 32
  • 56
  • Everything worked before in view, but now I get `undefined method `each' for nil:NilClass` what is talking about `@perfomance_report`. Can you suggest why it is happening ? – MID Sep 05 '12 at 10:16
  • 1
    first thing remove your index method from private and paste it above...check in console that if the selected website has any performance_reports and run each on instance variable `@performance_reports` not on `@performance_report` as it is the correct instance variable – abhas Sep 05 '12 at 10:21
  • You were right about private method, but how I can make privated only for before filter ? Put it in the bottom of the file ? – MID Sep 05 '12 at 10:25
  • 1
    ya in the end and put only before_filter methods after private for e.g. load_website not actions.. – abhas Sep 05 '12 at 10:29