数据库到 CRUD 应用程序,Rails 3

发布于 2024-10-13 07:50:28 字数 274 浏览 4 评论 0原文

我有一个相当大的数据库模式和大约 100M 行,我想使用 Rails 3 公开到网络。通过公开到网络,我的意思是:

  • 一个 REST api(json 和 xml)
  • 视图来呈现数据 分层
  • 数据特定部分的

编辑器基本上,我正在寻找一种使用适当的参数自动运行railsscaffold命令的方法。我知道 magic_model 本身可以完成逆向工程的某些部分,但它似乎不适用于 Rails 3。

有没有任何工具可以自动生成脚手架?

I have a fairly large DB schema and about 100M rows with I would like to expose to the web, using Rails 3. By exposing to the web, I mean the following:

  • A REST api (json & xml)
  • Views to present the data hierarchically
  • Editors for specific parts of the data

Basically, what I am looking for is a way to run the rails scaffold command with the appropriate arguments automatically. I know that magic_model can do some parts of the reverse engineering itself, but it does not seem to be working with Rails 3.

Is there any tool that can automate the generation of scaffolding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我不是你的备胎 2024-10-20 07:50:28

您可以尝试以下宝石:

  • ActiveAdmin
    ->虽然更多的是管理框架,但它有一个令人愉悦的用户界面,可以很好地满足您的脚手架需求。

  • ActiveScaffold ->一个简单的自动脚手架生成框架

You could give the following gems a try:

  • ActiveAdmin
    -> Though more of admin framework, it has an appeasing user interface and will aptly satisfy your scaffolding needs.

  • ActiveScaffold -> A simple auto-scaffold generation framework

淡莣 2024-10-20 07:50:28

我只是稍微改变了我的一个脚本:

#!/usr/bin/env ruby

require 'rubygems'
require 'active_record'
require 'active_support'
require 'logger'

require 'fileutils'

ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))

ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))



for table in ActiveRecord::Base.connection.tables  

  table_class=table.classify
  eval("class #{table_class} < ActiveRecord::Base;set_table_name \"#{table}\";end")

  columns = []
  for column in Kernel.const_get(table_class).columns
      columns << "#{column.name}:#{column.type}"
  end

  puts "rails generate scaffold #{table_class} #{columns.join(' ')}"

end

我在我的数据库上尝试了它(我只使用mysql),我认为它的输出非常好。基本上它打印脚手架命令。我不知道这对您来说是否是一个好的解决方案,但恕我直言,这是一个公平的起点。

I just changed a bit a script of mine:

#!/usr/bin/env ruby

require 'rubygems'
require 'active_record'
require 'active_support'
require 'logger'

require 'fileutils'

ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))

ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))



for table in ActiveRecord::Base.connection.tables  

  table_class=table.classify
  eval("class #{table_class} < ActiveRecord::Base;set_table_name \"#{table}\";end")

  columns = []
  for column in Kernel.const_get(table_class).columns
      columns << "#{column.name}:#{column.type}"
  end

  puts "rails generate scaffold #{table_class} #{columns.join(' ')}"

end

I tried it on a database of mine (I use only mysql) and I think its output is quite good. Basically it prints the scaffold commands. I don't know if it is a good solution for you but it's a fair starting point IMHO.

鱼忆七猫命九 2024-10-20 07:50:28

您可以使用reverse_scaffold。它的作用正如其名称所暗示的那样,即从遗留数据库中的现有表自动创建脚手架。

你可以在github上找到它:

https://github.com/chrugail/reverse_scaffold(rails 3版本)

还有ahe(原作者)的rails 2版本

You can use reverse_scaffold. It does what the name implies, i.e. Automatically creates the scaffolding from existing table in the legacy database.

You can find it on github:

https://github.com/chrugail/reverse_scaffold (rails 3 version)

There is also a rails 2 version by ahe (the original author)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文