派生的Activerecord Ruby类

我对ruby完全不熟悉。 我正在尝试为任务跟踪应用程序创建RESTful服务。 我研究并发现Sinatra比铁路更好。 所以我使用的是Sinatra和ActiveRecord。 我正在跟随Sinatra和ActiveRecord运行 。 我将使用Restsharp在.NET中创建客户端应用程序。 但这都是关于服务器端的。

这是我创建的迁移

class CreateTasksPeopleDocumentsAndComments < ActiveRecord::Migration def self.up create_table :tasks do |t| t.string :name t.string :task_status t.string :task_type t.text :description t.text :analysis t.text :investigation t.integer :developer_id t.integer :reviewer_id t.date :open_date t.date :analysis_date t.date :promotion_date t.date :review_date t.date :correction_date t.date :collection_date t.date :closed_date t.date :modified_date t.date :target_date end create_table :people do |t| t.string :name t.string :trigram t.string :state t.string :level end create_table :documents do |t| t.string :name t.binary :data t.string :path t.integer :task_id t.integer :developer_id end create_table :comments do |t| t.text :comment t.datetime :comment_timestamp t.integer :person_id t.integer :task_id t.integer :comment_id end end def self.down drop_tables :tasks drop_tables :people drop_tables :documents drop_tables :comments end end 

和主App.rb

 class Person < ActiveRecord::Base end class Developer < Person has_many :tasks end class Reviewer < Person has_many :tasks end class Task < ActiveRecord::Base belongs_to :developer belongs_to :reviewer has_many :documents end class Document < ActiveRecord::Base belongs_to :task belongs_to :developer end class Comment  "AEonAX", :trigram =>"anx", :state => "Active", :level => "Master" ) person2 = Person.create( :name => "XEonAX", :trigram =>"xnx", :state => "Inactive", :level => "User" ) person3 = Person.create( :name => "ZEonAX", :trigram =>"znx", :state => "Active", :level => "User" ) person4 = Person.create( :name => "LEonAX", :trigram =>"lnx", :state => "Inactive", :level => "Master" ) task1 = Task.create( :name => "IR-000001V0R2000", :description => "The Very First Incident Report", :task_status => "Opened", :task_type => "Internal", :developer_id => person2.id, :reviewer_id => person1.id ) task2 = Task.create( :name => "IR-000002V0R2000", :description => "Second Incident Report", :task_status => "Tech. Anal.", :task_type => "External", :developer_id => person2.id, :reviewer_id => person1.id ) task3 = Task.create( :name => "IR-000003V0R2000", :description => "Another Incident Report", :task_status => "Under Corr.", :task_type => "External", :developer_id => person3.id, :reviewer_id => person1.id ) document1 = Document.create( :name => "FirstDoku", :path => "\\XEON-NB\Test\FiddlerRoot.cer", :task_id => task1.id, :developer_id => task1.developer.id, :data => Task.all.to_json #SomeBinaryData ) end 

目前,此代码仅读取数据。 我还没有开始写数据。 基本上,关系就像一个任务,将有一个开发人员和审查人员。 它将附有文件。 它也会有评论。 评论可以在任务上或回复评论。 正如您所看到的,我已经声明了一个Person类,并从中派生了DeveloperReviewer 。 这是正确的方法吗? 欢迎任何其他建议。 甚至接受使用其他框架的建议。