正常的情况下,例如编辑一个用户时,链接是 http://localhost:3000/users/2/edit , 编辑完成后自动跳转到 http://localhost:3000/users/2 .
但是我新建的一个页面,编辑页面链接是http://localhost:3000/factors/10/edit , 编辑完成后自动跳转到了http://localhost:3000/factor.10,然后报错提示:
ActionController::RoutingError (No route matches [PATCH] "/factor.10"):
像这种情况,是在哪里设置编辑完成后跳转的正确地址http://localhost:3000/factor/10呢?
controller 里对应的方法代码是:
def update
@factor= Factor.find(params[:id])
@result= Result.find_by(factor_id: @factor.id)
if @factor.update_attributes(factor_params)
calculate_result(@factor,@result)
flash[:success] = "更新成功"
redirect_to @result
else
render 'edit'
end
end