在 Rails 中的订单处理过程中捕获地址信息
我正在 Rails 中构建一个电子商务应用程序,希望对我的模型关系以及如何使用信息填充表格提供一些帮助。
我有一个用户模型、一个订单模型和一个地址模型。我想在订购过程中以表格形式捕获地址。 在我的订单模型中,我有 user_id、pay_type、电子邮件、address_id 和姓名。 在我的地址中,我有 user_id(然后是一些地址字段)。
因此,
order belongs_to a user
address belongs_to a user
address belongs_to an order
order has_one address
user has_many orders
user has_one address
当客户单击结账时,我希望他们输入订单上的姓名、电子邮件、地址和付款类型。 user_id 将使用当前登录的用户方法通过隐藏字段捕获。 (如果有更好的方法请告诉我)。抱歉,如果这没有得到很好的解释
I am building an ecommerce app in rails and would like some help on my model relationships and how i get the tables populated with the information.
I have a user model, an order model and an address model. I want to capture the address in a form during the order process.
In my order model i have user_id, pay_type, email, address_id and name.
In my address I have the user_id, (then some address fields).
the relationships are
order belongs_to a user
address belongs_to a user
address belongs_to an order
order has_one address
user has_many orders
user has_one address
So when a customer clicks checkout I want them to enter the name thats on the Order, email, address and paytype. The user_id will be captured using currently signed in user method through a hidden field. (If there is a better way let me know). sorry if this isn't explained very well
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要研究accepts_nested_attributes 和嵌套表单。
或者只是浏览一些代码这里,例如
主要这里需要注意的是:
You'll need to look into accepts_nested_attributes and nesting forms.
Or just look through some code here, e.g.
The main things here to note are: