我是新人,所以请原谅我完全的无知。我在 Rails 3.2.3 上,正在学习 Lynda Ruby on Rails Essentials 课程。我已完成标题中列出的章节,但在确认删除按钮后出现错误页面。这是一个视频,向您展示操作中的错误。
我查看了以下文档以确认我没有输入错误。
这是我的 list.html.erb
<div class="subject list">
<h2>Subjects</h2>
<%= link_to("Add New Subject", {:action => 'new'}, :class => 'action new') %>
<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", {:action => 'edit', :id => subject.id}, :class => 'action edit') %>
<%= link_to("Delete", {:action => 'delete', :id => subject.id}, :class => 'action delete') %>
</td>
</tr>
<% end %>
</table>
这是我的 delete.html.erb
<%= link_to("<< Back to List", {:action => 'list'}, :class => 'back-link') %>
<div class="subject delete">
<h2>Delete Subject</h2>
<%= form_for(:subject, :url => {:action => 'destroy'}, :id => @subject.id) do |f| %>
<p>Are you sure you want to permanently delete this subject?</p>
<p class="reference-name">Subject name: <%= @subject.name %></p>
<div class ="form-buttons">
<%= submit_tag("Delete Subject") %>
</div>
<% end %>
</div>
这是我的subjects_controller.rb
class SubjectsController < ApplicationController
def index
list
render('list')
end
def list
@subjects = Subject.order("subjects.position ASC")
end
def show
@subject = Subject.find(params[:id])
end
def new
@subject = Subject.new
end
def create
# Instantiate a new object using form parameters
@subject = Subject.new(params[:subject])
# Save the object
if @subject.save
# If save succeeds, redirect to the list action
redirect_to(:action => 'list')
else
# If save fails, redisplay the form so user can fix problems
render('new')
end
end
def edit
@subject = Subject.find(params[:id])
end
def update
# Find object using form parameters
@subject = Subject.find(params[:id])
# Update the object
if @subject.update_attributes(params[:subject])
# If save succeeds, redirect to the list action
redirect_to(:action => 'show', :id => @subject.id)
else
# If save fails, redisplay the form so user can fix problems
render('edit')
end
end
def delete
@subject = Subject.find(params[:id])
end
def destroy
Subject.find(params[:id]).destroy
redirect_to(:action => 'list')
end
end
这是上面视频中引用的结果错误页面。
如果我能得到一些帮助来理解为什么我不能正确删除文件,那就太好了。