所以我正在做lynda.com铁道课程。
由于为rails 3.1录制了课程,我现在正在使用Rails 4,现在他们正在强制执行strong_parameters。我添加了subject_params定义以符合这一点,但是当我尝试在我之前声明的类节目中获取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
答案 0 :(得分:0)
尝试添加:created_at
和:updated_at
并删除:id
像这样:
(params.require(:subject).permit(:name, :position, :visible, :created_at, :updated_at)