RoR 或 Sinatra 插入多个 MySql 表
我们有一个 php 网站,目前充当注册门户。我想将其移植到 RoR 或 Sinatra。
当用户注册时,他们输入自己的姓名和电子邮件。注册页面包含一些其他隐藏变量,包括它们属于哪个组。当他们提交表单时,我们使用 php 执行以下操作:
- 将姓名、电子邮件和密码插入用户表
- 将组名和其他一些属性插入组表
我们有多个 sql 函数执行此操作。
问题 1:
如何在 RoR 应用程序中执行此操作?我可以创建一个包含一些隐藏变量的嵌套表单,但我不知道如何将数据插入到几个表中?我必须创建某种协会吗?
问题2:
如何防止用户篡改隐藏变量?如果在 html 中将组从 A 更改为 B 并提交,我希望应用程序知道。
We have a php website that currently acts as a registration portal. I want to port this to RoR or Sinatra.
When a user signs up, they enter their name and email. The sign-up page contain some other hidden variables, including which group they belong to. Using php when they submit the form we do this:
- insert into name, email and password into usertable
- insert groupname and some other attributes into grouptable
We have multiple sql functions do this.
Question 1:
How do I do this in a RoR app? I can create a nested form with some hidden variables but I do not know how to insert the data in to a couple of tables? Do I have to create some kind of association?
Question 2:
How can I prevent the users from tampering with the hidden variables? If the change the group from A to B in the html and submit, I want the app to know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设该组以某种方式由服务器确定(路径,一些随机变量,其他),因此,不要将其传递给客户端,而是在生成页面时将其存储在该用户的会话中,并在读取响应时读取它。
I assume that the the group is in some way determined by the server (path, some random variable, something else), so, instead of passing it down to the client, store it in the session for that user when the page is generated, and read it when the response is read.