<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;You can use a hobo generator to create a model&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
ruby script/generate hobo_model &amp;lt;model_name&amp;gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;where &lt;model_name&gt; should be the singular model_name instead of the class name ModelName or the plural model_names.&lt;/p&gt;
&lt;p&gt;If the model is going to have views it needs a controller and you can create both model and controller at the same time by&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
ruby script/generate hobo_model_resource &amp;lt;model_name&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;This creates a bunch of stuff&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
D:\workspace\TryHobo&amp;gt;ruby script\generate hobo_model_resource my_model
      exists  app/models/
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/my_models
      exists  test/functional/
      exists  test/unit/
  dependency  hobo_model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
      create    app/models/my_model.rb
      create    test/unit/my_model_test.rb
      create    test/fixtures/my_models.yml
      create  app/controllers/my_models_controller.rb
      create  test/functional/my_models_controller_test.rb
      create  app/helpers/my_models_helper.rb

D:\workspace\TryHobo&amp;gt;cd app

D:\workspace\TryHobo\app&amp;gt;cd models

D:\workspace\TryHobo\app\models&amp;gt;dir
 Volume in drive D is DATA
 Volume Serial Number is 1440-4E18

 Directory of D:\workspace\TryHobo\app\models

10/13/2008  03:02 PM    &amp;lt;DIR&amp;gt;          .
10/13/2008  03:02 PM    &amp;lt;DIR&amp;gt;          ..
10/09/2008  02:30 PM               202 guest.rb
10/13/2008  03:02 PM               377 my_model.rb
10/09/2008  02:45 PM               444 project.rb
10/09/2008  02:46 PM             1,712 user.rb
10/09/2008  02:30 PM               440 user_mailer.rb
               6 File(s)          3,668 bytes
               2 Dir(s)  176,363,552,768 bytes free

D:\workspace\TryHobo\app\models&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Let us look at my_model.rb&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
class MyModel &amp;lt; ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    timestamps
  end


  # --- Hobo Permissions --- #

  def creatable_by?(user)
    user.administrator?
  end

  def updatable_by?(user, new)
    user.administrator?
  end

  def deletable_by?(user)
    user.administrator?
  end

  def viewable_by?(user, field)
    true
  end

end

&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Fields are defined here&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
  fields do
    name :string
    timestamps
  end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;#8220;name&amp;#8221; is a good field to define in the model because if you define it, later you can reference a model with &amp;#8220;this&amp;#8221; and the convention will be to use the name field when creating links to the model record.  Also &amp;lt;model&amp;gt;.to_s will return the name field value.&lt;/p&gt;
&lt;p&gt;Here are some examples of different field definitions&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
  fields do
    name            :string
    required_string :string, :required
    unique_string   :string, :unique
    in_use          :boolean, :default =&amp;gt; false
    status          enum_string(:new, :selected, :hidden), :default =&amp;gt; :new    
    comments        :text, :limit=&amp;gt;2000
    publish_date    :date
    dt              :datetime
    amount          :decimal, :precision =&amp;gt; 8, :scale =&amp;gt; 2 
    cycle_length    :integer
    timestamps
  end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;a boolean field will be stored as a tinyint(1) where 0=false and 1=true if using MySQL&lt;br /&gt;
&lt;br/&gt;&lt;br/&gt;enum_string lets you define static coded strings, this example will store the values &amp;#8220;new&amp;#8221;, &amp;#8220;selected&amp;#8221;, or &amp;#8220;hidden&amp;#8221; into a field named &amp;#8220;status&amp;#8221;&lt;br /&gt;
&lt;br/&gt;&lt;br/&gt;the amount field is defined as a fixed decimal number with 6 places before the decimal and 2 places after.&lt;br /&gt;
&lt;br/&gt;&lt;br/&gt;timestamps declares two :datetime fields updated_at and created_at which are automatically set to the current datetime when adding or updating records&lt;/p&gt;</body>
  <created-at type="datetime">2008-10-13T13:58:09-07:00</created-at>
  <id type="integer">66846</id>
  <permalink>models</permalink>
  <repository-id type="integer">3773</repository-id>
  <title>Models</title>
  <updated-at type="datetime">2008-10-17T11:38:05-07:00</updated-at>
  <user-id type="integer">22366</user-id>
</wiki>
