我正在关注 Rails 上的 Lynda 教程,除了包含相应信息的 list.html.erb 文件之外,我还定义了列表操作。
但是,当我继续访问 ~/subjects/list 时,我得到了这个:
未知动作
找不到 SubjectsController 的操作“显示”
这是来自我的控制器的代码:
class SubjectsController < ApplicationController
def list
@subjects = Subject.order("subjects.position ASC")
end
end
谢谢!
更新:这就是我从 Rake 路线中得到的
rake routes
subjects GET /subjects(.:format) subjects#index
POST /subjects(.:format) subjects#create
new_subject GET /subjects/new(.:format) subjects#new
edit_subject GET /subjects/:id/edit(.:format) subjects#edit
subject GET /subjects/:id(.:format) subjects#show
PUT /subjects/:id(.:format) subjects#update
DELETE /subjects/:id(.:format) subjects#destroy
更新:
视图 list.html.erb 的代码:
<div class="subject list">
<h2>Subjects</h2>
<table class="listing" summary="Subject list">
<tr class="header">
<th> </th>
<th>Subject</th>
<th>Visible</th>
<th>Pages</th>
<th>Actions</th>
</tr>
<% @subjects.each do |subject| %>
<tr>
<td><%= subject.position %></td>
<td><%= subject.name %></td>
<td class="center"><%= subject.visible ? 'Yes' : 'No' %></td>
<td class="center"><%= subject.pages.size %></td>
<td class="actions">
<%= link_to("Show", {:action => 'show', :id => subject.id}, :class => 'action show') %>
<%= link_to("Edit", '#', :class => 'action edit') %>
<%= link_to("Delete", '#', :class => 'action delete') %>
</td>
</tr>
<% end %>
</table>
</div>