Sinatra - 如何最好地在页面之间移动变量/参数

发布于 2024-12-22 11:12:53 字数 174 浏览 3 评论 0原文

我有一个注册页面,其中包含常用的电子邮件、姓名、密码……该页面在服务器提交的路由/页面中进行了验证。如果失败,那么我重定向回来,但我想将值填回到注册页面中。我可以将注册表单参数放入会话中,但它将保留在那里...是否有页面内存(范围比会话更小) )就像会话一样,它仅用于下一页,然后消失/这是实现此目的的最佳方法。

谢谢

I have a register page with the usual email,name,password ..which is validated in the server's submitted route/page. if it fails then I redirect back but I want to fill the values back in the register page..I can put the register form parameters in the session but it will stay there...is there a page memory(a smaller scope than session) just like session which will be just for the next page and then gone/ which is the best way to implement this.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄暮涼年 2024-12-29 11:12:54

为什么不直接从 POST 路由渲染注册页面,如下所示:

post '/register' do
  @registration_data = params[:stuff] # store all your registration data
  if info_validates  # everything validates
    redirect './user_home'
  else  # something fails validation
    haml :register  # or erb or whatever your template engine is
  end
end

然后在您的视图中,填充 @registration_data(如果存在)。

此外,您还可以使用 session.clear 清除会话数据。

Why don't you just render the registration page from the POST route like this:

post '/register' do
  @registration_data = params[:stuff] # store all your registration data
  if info_validates  # everything validates
    redirect './user_home'
  else  # something fails validation
    haml :register  # or erb or whatever your template engine is
  end
end

Then in your view, have it fill in @registration_data if it exists.

Also, you can clear session data with session.clear.

吝吻 2024-12-29 11:12:54

Ajax 验证会容易得多。您只需向表单提交按钮注册一个 onclick 事件,该事件会调用一个页面,该页面返回带有错误信息的 json 状态代码,或者返回 200 表示“正常”。如果是200,则提交。

Ajax validation would be much easier. You just register an onclick event to your form submit button that makes a call to a page that returns a json status code with the error information or 200 for OK. If 200, then submit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文