更新后找不到模板
No template found after Update
又是我。昨天我的两个问题解决后,让我们再试一个。这次在Rails.
上Ruby的update函数有些问题
所以,主要是更新做得很好。它保存了新数据并且一切正常,期待一件事:当我单击 "save" 按钮时,前端没有任何反应。正如我所说,数据已正确更新,但我认为应该 redirect
到 root_path
因为有重定向。你能告诉我我做错了什么吗?我用其他 redirects/render 尝试了几件事,但没有任何效果。
此代码是我的控制器的一部分:
def update
@resume = Resume.find(params[:id])
if @resume.update_attributes(resume_params)
flash[:success] = 'The file has been updated!'
redirect_to root_path
else
render 'edit'
end
end
这是我在日志中得到的错误:
No template found for ResumesController#update, rendering head :no_content
Completed 204 No Content in 96ms (ActiveRecord: 21.1ms)
提前致谢!
这对我有用,如果它保存在数据库中,希望它也对你有用。使用 'Alert' 而不是 'Flash'。我已经根据您的代码更改了代码。
def update
@resume = Resume.find(params[:id])
if @resume.update(profile_params)
redirect_to root_path, alert: "Your resume is saved!"
else
render 'edit', alert: "Oops! There was a problem, please try again"
end
end
又是我。昨天我的两个问题解决后,让我们再试一个。这次在Rails.
上Ruby的update函数有些问题所以,主要是更新做得很好。它保存了新数据并且一切正常,期待一件事:当我单击 "save" 按钮时,前端没有任何反应。正如我所说,数据已正确更新,但我认为应该 redirect
到 root_path
因为有重定向。你能告诉我我做错了什么吗?我用其他 redirects/render 尝试了几件事,但没有任何效果。
此代码是我的控制器的一部分:
def update
@resume = Resume.find(params[:id])
if @resume.update_attributes(resume_params)
flash[:success] = 'The file has been updated!'
redirect_to root_path
else
render 'edit'
end
end
这是我在日志中得到的错误:
No template found for ResumesController#update, rendering head :no_content
Completed 204 No Content in 96ms (ActiveRecord: 21.1ms)
提前致谢!
这对我有用,如果它保存在数据库中,希望它也对你有用。使用 'Alert' 而不是 'Flash'。我已经根据您的代码更改了代码。
def update
@resume = Resume.find(params[:id])
if @resume.update(profile_params)
redirect_to root_path, alert: "Your resume is saved!"
else
render 'edit', alert: "Oops! There was a problem, please try again"
end
end