Tuesday, February 28, 2012

Rails scaffolding types

These types are valid since Rails version 2:

  • string
  • text (long text, up to 64k, often used for text areas)
  • datetime
  • date
  • integer
  • binary
  • boolean
  • float
  • decimal (for financial data)
  • time
  • timestamp

Here is an example of using rails 3.x scaffolding with data types, run from the Rails application root directory:

ruby script/rails generate scaffold Modelname name:string title:string employed_on:date remarks:text

4 comments:

  1. ruby script/rails generate scaffold Modelname name:string title:string employed_on:date remarks:text
    it is rails2

    ReplyDelete
  2. VeGeek,

    It still works in rail 3.0. I've used it recently with rails 3.0.3.

    Keith

    ReplyDelete
  3. Awesome! This is exactly what I was looking for.

    1. Where do you find a comprehensive list for Rails 3?
    I tried running "rails g scaffold" but it still doesn't list all the types.

    2. Can scaffold generate a file upload field? I've tried :file, but it doesn't work. What would I use for that?

    ReplyDelete
  4. Benxamin,

    I'm not sure where to find a comprehensive list of all scaffold types, but I don't think there is one for a file upload field. There is a rails form helper for file upload documented here:

    http://guides.rubyonrails.org/form_helpers.html#uploading-files

    ReplyDelete