我有一个相当标准的控制器,带有一个创建方法和一些验证。
def create
@type = Type.new(params[:type])
respond_to do |format|
if @type.save
format.html { redirect_to types_path, notice: 'Type was successfully created.' }
format.json { render json: @type, status: :created, location: @type }
else
format.html { render action: "new" }
format.json { render json: @type.errors, status: :unprocessable_entity }
end
end
end
问题是,当验证失败时,我得到错误Missing template ontology/types/create
,就好像render action: "new"
不存在一样。如果我用 a 替换它,redirect_to
那么它会按预期工作,但似乎我无法传递表单错误。
我知道在 new 的原始调用中有一个 @type 实例(带有 @type.errors),并在渲染调用确认这一点之前将其抛出。
当更新验证失败时也会发生同样的事情看起来渲染调用被忽略了!
注意:我的路由结构有点不合常规,但我看不出这应该相关的原因。