gpt4 book ai didi

ruby-on-rails-3 - 导轨 3 : Rendering actions with named anchors/fragments after failed form submission

转载 作者:行者123 更新时间:2023-12-04 19:35:12 24 4
gpt4 key购买 nike

我的一个模型的编辑 View 包含选项卡,这些选项卡利用 url 中的 anchor 在 model/1/edit#tab1 和 model/1/edit#tab2 等设置之间切换。有没有办法在提交编辑表单但由于错误而无法保存后重定向到这些 anchor ?我当前的代码如下:

  def update
@user = Product.new(params[:user])
if @user.save
flash[:success] = "Your user has been created"
redirect_to @user
else
render 'edit' //want to render here with an anchor
end
end

我想在提交表单之前存储包含 anchor 的 url,然后在呈现错误消息时使用相同的 anchor 重新呈现表单。有什么想法吗?

最佳答案

最好的方法是使用 jquery cookie保存最后打开的选项卡,然后使用保存的 cookie 设置默认选项卡。

关于ruby-on-rails-3 - 导轨 3 : Rendering actions with named anchors/fragments after failed form submission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12337244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com