所以我正在学习lynda.com rails课程。
由于该课程是为rails3.1录制的,我现在使用的是Rails4,他们现在正在强制执行strong_parameters。我添加了subject_params定义来遵守这一点,但现在当我试图在之前声明的类show上获取params[:id]时,我得到了ActiveRecord::RecordNotFound。下面是代码。方法显示以前运行良好。
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
尝试添加:created_at
和:updated_at
并删除:id
像这样:
(params.require(:subject).permit(:name, :position, :visible, :created_at, :updated_at)