所以我正在学习 lynda.com rails 课程。
由于课程是为 rails 3.1 录制的,我现在在 Rails 4 上,他们现在正在执行 strong_parameters 。我添加了 subject_params 定义以符合这一要求,但现在当我尝试在我之前声明的类节目中获取 params[:id] 时,我得到了 ActiveRecord::RecordNotFound。下面是代码。方法 show 之前工作正常。
class SubjectsController < ApplicationController
def show
@subject = Subject.find(params[:id])
end
def new
@subject = Subject.new(:name => 'default')
end
def create
# Instantiante a new object using form parameters
@subject = Subject.new(subject_params)
# Save the object
if @subject.save
# If save suceeds, 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
private
def subject_params
params.require(:subject).permit(:id, :name, :position, :visible)
end
end