将Rails应用程序连接到现有数据库 [英] Connect Rails Application To Existing Database

查看:84
本文介绍了将Rails应用程序连接到现有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户要求我帮助他们构建一个ruby应用程序,以与为在php上运行的其他应用程序创建的数据库交互.问题在于,由于数据库没有被Rails束缚,因此它不遵循任何Rails约定.例如,有一个名为 form

I have a client asking me to help them build a ruby application to interface with a database that was created for a different application that runs on php. The problem is that since the database was not scaffolded with rails, it does not follow any of the rails conventions. For example, there is a table called form

如果我运行命令 rails generate model form ,那么rails将推断表名称为form s

If I run the command rails generate model form then rails will infer the table name is forms

此外,我不希望ruby执行任何迁移,因为数据已经以我想要的状态存在.有什么好办法吗?

further more I don't want ruby to perform any migrations since the data is already there in the state that I want it. Is there any good way of going about this?

推荐答案

您无需运行迁移即可拥有模型.跳过它们(-no-migration )或在生成后删除文件.至于表名,请查看 table_name = . primary_key = 也可能很方便.

You don't need to run migrations to have the model. Either skip them (--no-migration) or remove the file after generating. As for table names, look at table_name=. primary_key= may also be handy.

class Form << ActiveRecord::Base
  self.table_name = 'form'
end

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆