为 has_many & 创建连接表属于协会
Rails 3 新手在这里...我正在努力创建一个设计身份验证系统,例如(yammer)具有用户所属的实例。我有两个表
用户(电子邮件、密码...) belongs_to :instance
实例(域名、活动......) has_many :users
我将belongs_to和has_many添加到模型中,但架构尚未更新以添加连接,我相信这将是用户表中的instance_id列。 Rails 3 中如何实现这一点?想法、建议?
Rails 3 newbie here... I'm working to create a devise auth system that like (yammer) has instances where users belong. I have two tables
Users (email, password...)
belongs_to :instance
Instance (domain name, active....)
has_many :users
I added the belongs_to and has_many to the models but the schema hasn't been updated to add the join, which I believe would be an instance_id column to the User's table. How does this get accomplished in Rails 3? Thoughts, suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须通过迁移将这些列添加到架构中。
http://guides.rubyonrails.org/migrations.html
尝试:
script/rails 生成迁移AddInstanceToUsers
然后转到 db/migrations 文件夹查找新文件并使其看起来像:
运行。
然后在控制台中
You have to add these columns to the schema by migrations.
http://guides.rubyonrails.org/migrations.html
Try:
script/rails generate migration AddInstanceToUsers
then go to your db/migrations folder look for the new file and make it look like:
then run
in your console.