问题描述
我给自己的一个小项目,以帮助我提高我的Ruby on Rails的编程。到目前为止,我已经完成了完整的用户注册和认证密码复位,还记得我的功能和通知邮件。我完全明白是怎么回事。
I've giving myself a small project to help me improve with my ruby on rails programming. So far I've completed full user signup and authentication with password reset, a remember me feature and notification emails. I totally understand what is going on.
所以,我现在已经转移到用户帐户区,想code,我的用户可以编辑自己的个人资料页面。我的注册表格只要求提供用户名,电子邮件地址和密码,因为我想快速注册。对于其中用户可以编辑自己的个人资料信息的页面,会要求他们的东西,如:
So I've now moved to the user account area and would like to code the page that my user would edit their profile on. My signup form only asked for username, email and password as I wanted quick registration. For the page where users will edit their profile information it will ask them for things such as:
第一个名字姓出生日期位置这将有网址为他们的个人资料关于我个人统计favoyrite东西状态等和他们的照片
first namelast namedate of birthlocationit will have the url for their profileabout mepersonal statsfavoyrite thingsstatus etcand their photos
他们应该能够更新或更改飞这个信息。在他们的实际个人资料页面就会拉出此信息为他们的个人资料的内容。
They should be able to update or change this info on the fly. On their actual profile page it will pull this info for their profile content.
我想知道,以保持组织会是最好创建一个单独的表这个如个人资料?或者会是明智的存储一些在用户表这个信息在数据库中,如名字姓氏?
I was wondering to keep organised would it be best to created a separate table for this e.g. profile? or would it be wise to store some of this info in the users table in the database, such as first name last name?
我试图找出一个干净的方式来做到这一点,因为后来我将需要添加更多的页面,如设置页面等。
I'm trying to figure out a clean way to do this because later on I'll need to add more pages like the settings page etc.
这是我第一次将与多个表来工作,我有一个想法如何做到这一点,但也不太清楚。任何意见,如你将如何实现这一目标将是AP preciated一个简要的解释。
This is the first time I'll be working with multiple tables and I have an idea how to do it but not too sure. Any advice such as a brief explanation of how you would achieve this would be appreciated.
问候
推荐答案
我知道我会得到防弹从人民简单化主观情况。但在次左右,使主观上的情况可以在决策帮助的情况进行公开讨论。所以,这里是我的作为。
I know I will get flak from people for oversimplifying a subjective situation. But at times an open discussion around the scenarios that make the situation subjective can help in decision making. So, here is my take.
您使用或设计一些这样的创业板的认证件?如果是的话,那么你可能有每个创业板的要求创建的表。如果你看一下的关注,无论是需要认证+授权系统分离是pretty的在现有的用户表要包围。我会问接近它 - 是有耦合您的个人资料数据(特别是如果它是一个多几个文本字段)与此表中的任何好处?我没有看到一个特别鉴于配置文件或用户生成的数据永久不再保证只是一张图片和2-3文本字段。例如,在社交网站上的个人资料可以利用它自己的生命。
Are you using devise or some such gem for the authentication piece? If yes then you probably have the tables created per the requirements of that gem. If you look at separation of concerns, whatever is needed for the authentication + authorization system is pretty much encompassed in your existing user table. I would approach it by asking - is there any benefit of coupling your profile data (especially if it is more than a couple of text fields) with this table? I don't see one especially given the fact that profiles or user-generated permanent data are no longer guaranteed to be just one picture and 2-3 text fields. For example, on social networking sites the profile can take a life of its own.
此外,会发生什么情况。如果您有添加/更新图片,位置信息和其他数据的轮廓活跃的用户群,你想那开始影响您的身份验证表?如果你打了资源危机,一个独立的认证系统可以是你最后的问题。但并非如此,如果它已被加上一切用户相关
Also, what happens if your site takes off. If you have an active user base that adds/updates pics, location info and other data to the profile, do you want that to start impacting your authentication tables? If you hit a resource crunch, a standalone authentication system can be your last concern. But not so if it has been coupled with everything user-related.
所以,是的,它不依赖于特定的情况,但我希望我的上述想法为你为何决定可能不同根据网站的类型一定的清晰度。如果用户是在您的系统和用户交互的心脏是关键配置文件(如社交网络)肯定想保持分开的两个领域。如果用户配置文件可能只是单行有关用户的话,就不是一个大问题。如果你这样做纯粹是为了学习,尝试一下两种方式,因为你将不得不为未来的挑战,更多的武器。
So, yes it does depend on your particular circumstance but I hope my thoughts above provide you some clarity on why the decision may differ based on the type of the site. If the user is at heart of your system and user interactions are key to the profile (e.g. social networks) definitely think about keeping the two areas separated. If user profile is probably just one-line about the user then it is not a big concern. If you are doing this purely for learning, try it out both ways because you will have more arsenal for future challenges.
这篇关于如何有效地与Ruby on Rails中多个数据库表工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!