Ruby on Rails - 将表单数据直接提交到会话变量
我花了几个小时试图找到一个资源来解释将表单数据直接提交到会话变量的过程,但我没有找到任何东西!
本质上,我不想在用户以这种特定表单提交时将数据存储在数据库中,我只是希望在用户提交表单时将其分配给 session[:member_pin]
变量,这样我就可以检查他们输入的 PIN 码是否与会员数据库记录上的 PIN 码匹配。
如果您需要进一步澄清我正在尝试做的事情,请告诉我,非常感谢您的帮助!
I have spent hours trying to find a resource that explains the process of submitting form data directly to a session variable, but I have had no luck finding anything!
Essentially I am not wanting to store the data in the database when the user submits in this particular form, I just want it to be assigned to the session[:member_pin]
variable when the user submits the form, so I can then check if the pin they entered matches the pin on the members database record.
Please let me know if you need anymore clarification for what I am trying to do, and thank you so much for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必在每次提交表单时都将数据保存到数据库中。在控制器的操作中,获取所需的参数并将它们存储在会话中。例如,
然后在您的应用程序控制器中,创建一个像这样的辅助方法。然后您应该能够在视图中访问“current_user”方法。 (如果您没有通过 pin 验证任何用户,则该值为零。
You don't have to save the data to database every time a form is submitted. In your controller 's action, get the params you want and store them in the session. Eg.,
Then in your application controller, make a helper method like this. Then you should be able to access "current_user" method in your views. (It will be nil if you haven't got any user verified with pins.
也许在你的控制器方法中是这样的:
maybe something like this in your controller method: