Ruby on Rails是否适合我想要实现的目标?为现有MySQL数据库创建CRUD脚手架

时间:2022-06-15 07:35:02

I have previously created localhost-only RoR applications where models were created manually with scaffolds generated for them, creating a nice, quick, easy to use CRUD interface for the data. I did this in Netbeans using SQLite.

我以前创建过localhost-only RoR应用程序,其中模型是使用为它们生成的支架手动创建的,为数据创建了一个漂亮,快速,易于使用的CRUD接口。我使用SQLite在Netbeans中做到了这一点。

Now I have a server with a MySQL database and wish to create a quick CRUD application which provides a quick and easy way to view data in the database and give a few options like edit/delete. As my database is already specified by MySQL this seems to open up a massive can of worms, making this a lot less straight forward in comparison to my Netbeans venture into scaffold-generated crud web apps in RoR.

现在我有一个带有MySQL数据库的服务器,并希望创建一个快速的CRUD应用程序,它提供了一种快速简便的方法来查看数据库中的数据,并提供一些选项,如编辑/删除。由于MySQL已经指定了我的数据库,这似乎开辟了大量的蠕虫病毒,与我的Netbeans在RoR中创建脚手架生成的crud web应用程序相比,这更不直接。

I have looked into dumping the schema of my current database, db:raking it, then generating the scaffolds. Is this the correct approach? I have also read about Magic Model Generator. Is this the best way to go about getting the MySQL database to a RoR model format? http://magicmodels.rubyforge.org/magic_model_generator/

我已经研究了转储当前数据库的模式,db:raking it,然后生成脚手架。这是正确的方法吗?我还读过有关Magic Model Generator的内容。这是将MySQL数据库变为RoR模型格式的最佳方法吗? http://magicmodels.rubyforge.org/magic_model_generator/

I guess what I'm asking is, for my database structure, is RoR appropriate to mock-up a quick CRUD web app so that the data can have basic manipulation performed on it?

我想我要问的是,对于我的数据库结构,RoR是否适合模拟快速CRUD Web应用程序,以便数据可以对其执行基本操作?

Below is the schema.rb for my MySQL database. There is a FK relationship on userId and attachmentId.

下面是我的MySQL数据库的schema.rb。 userId和attachmentId之间存在FK关系。

ActiveRecord::Schema.define(:version => 0) do

  create_table "attachments", :primary_key => "attachmentId", :force => true do |t|
    t.string "attachmentName",               :null => false
    t.string "fileType",       :limit => 30, :null => false
    t.binary "content",                      :null => false
    t.string "printCode"
  end

  create_table "emails", :primary_key => "emailId", :force => true do |t|
    t.integer "userId",       :limit => 11,   :null => false
    t.integer "attachmentId", :limit => 11,   :null => false
    t.string  "body",         :limit => 1000
    t.string  "subject"
  end

  add_index "emails", ["attachmentId"], :name => "attachmentId", :unique => true
  add_index "emails", ["userId"], :name => "userId"

  create_table "printUsers", :primary_key => "userId", :force => true do |t|
    t.string "email", :null => false
  end

  add_index "printUsers", ["email"], :name => "email", :unique => true

end

1 个解决方案

#1


1  

There seem to be several approaches to using rails with an existing database. See Connect rails to existing postgres DB - models not seen by console and controllers, and especially the links from it: http://magicmodels.rubyforge.org/magic_model_generator/ and http://blog.aizatto.com/2007/05/21/activerecord-without-rails/

似乎有几种方法可以将rails与现有数据库一起使用。请参阅将rails连接到现有的postgres数据库 - 控制台和控制器未看到的模型,尤其是来自它的链接:http://magicmodels.rubyforge.org/magic_model_generator/和http://blog.aizatto.com/2007/05/ 21 /了activerecord-而不-导轨/

It's good to point out that you don't need to use ActiveRecord with rails. Your model can be any Object, so it might be easier to use something like sequel or arel to access the data.

最好指出您不需要将ActiveRecord与rails一起使用。您的模型可以是任何对象,因此使用sequel或arel等内容访问数据可能更容易。

Another approach would be to migrate the data out of your existing database and into a new one that you generate by scaffolding your models.

另一种方法是将数据从现有数据库迁移到您通过脚手架模型生成的新数据。

#1


1  

There seem to be several approaches to using rails with an existing database. See Connect rails to existing postgres DB - models not seen by console and controllers, and especially the links from it: http://magicmodels.rubyforge.org/magic_model_generator/ and http://blog.aizatto.com/2007/05/21/activerecord-without-rails/

似乎有几种方法可以将rails与现有数据库一起使用。请参阅将rails连接到现有的postgres数据库 - 控制台和控制器未看到的模型,尤其是来自它的链接:http://magicmodels.rubyforge.org/magic_model_generator/和http://blog.aizatto.com/2007/05/ 21 /了activerecord-而不-导轨/

It's good to point out that you don't need to use ActiveRecord with rails. Your model can be any Object, so it might be easier to use something like sequel or arel to access the data.

最好指出您不需要将ActiveRecord与rails一起使用。您的模型可以是任何对象,因此使用sequel或arel等内容访问数据可能更容易。

Another approach would be to migrate the data out of your existing database and into a new one that you generate by scaffolding your models.

另一种方法是将数据从现有数据库迁移到您通过脚手架模型生成的新数据。