当我尝试访问此 url:http://localhost:3000/lessons/18/pages
时,出现此错误:
No route matches {:action=>"show", :controller=>"pages", :lesson_id=>#<Page id: 5,
title: "Page One", page_num: 1, lesson_id: 18, stats_id: nil, sources_id: nil,
created_at: "2012-04-06 04:55:39", updated_at: "2012-04-06 04:55:39">}
我有两张桌子:课程,页面
页面.rb
belongs_to :lessons
课程.rb
has_many :pages
路线.rb
resources :lessons do
resources :pages
end
页面索引如下所示:
<% @lesson.pages.each do |page| %>
<tr>
<td><%= page.title %></td>
<td><%= page.page_num %></td>
<td><%= page.lesson_id %></td>
<td><%= page.stats_id %></td>
<td><%= page.sources_id %></td>
<td><%= link_to 'Show', lesson_page_path(page) %></td>
<td><%= link_to 'Edit', edit_page_path(page) %></td>
<td><%= link_to 'Destroy', lesson_page, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
这是页面控制器:
def index
@lesson = Lesson.find(params[:lesson_id])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pages }
end
end
为什么show
路线不起作用?