Reputation: 1825
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 ?
Upvotes: 1
Views: 47
Reputation: 5213
In controller change the code to
@website = Website.find(params[:id])
Upvotes: 1