如何使用 Sinatra 进行发布/重定向/获取?
Sinatra 相当于 Rails 的 redirect_to
方法吗?我需要遵循表单提交的 Post/Redirect/Get 流程,同时保留传递到我的视图的实例变量。使用redirect
方法时实例变量会丢失。
What's Sinatra's equivalent of Rails' redirect_to
method? I need to follow a Post/Redirect/Get flow for a form submission whilst preserving the instance variables that are passed to my view. The instance variables are lost when using the redirect
method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sinatra 中的重定向是最简单易用的。
所以下面的代码可以解释:
您也可以像这样重定向到当前应用程序中的另一个路径,尽管此示例将删除一个方法。
使用此重定向指令的一个非常常见的地方是在“身份验证”下,
您可以在以下位置查看更多示例:
Sinatra 手册
常见问题解答
扩展
至于你的第二个问题,将变量传递到视图中,可能是这样的:
Redirect in Sinatra is the most simple to use.
So the code below can explain:
You can also redirect to another path in your current application like this, though this sample will delete a method.
A very common place where this redirect instruction is used is under Authentication
You can see more samples under:
Sinatra Manual
FAQ
Extensions
As for your second question, passing variables into views, it's possible like this:
Sinatra Book 应该可以解答您的问题。特别是“重定向”部分。
引自书中:
The Sinatra Book should clear your question. Especially the "Redirect" part.
Quoted from the book: