How should I model this?

Hi,
I am making a web application that basically allows user to create a
table. They name the table and add columns (field). Then they add
entries (rows), just like a typical table.

So for example, the user can create a table called "High-Scores". Then
add fields "Name", "Points", "Achievements". These 3 will be the
columns. Then they can add an entry, so for example, "John", "123",
"Gold".

How would I model this with a ruby class? Basically, from what I have
learned from tutorial so far, the models have predetermined fields. Now,
I have dynamic fields.

Thanks for your help.

A table has many columns and a columns belongs to a table. Each
column has many rows. Each row is a cell that would represent some
sort of data type. You'll probably have to store some sort of ordinal
to keep the rows and columns in order. It's gonna be slow. If you
have any 3GL experience, it would be a list of lists used as a multi-
dimensional array.

Another approach would be to have a limit on the number of columns and
allow the user to 'add' columns by actually unhiding them. This is
less dynamic, but a lot faster and simpler.

I am making a web application that basically allows user to create a
table. They name the table and add columns (field). Then they add
entries (rows), just like a typical table.

...

How would I model this with a ruby class?

I don't think you could easily do it with a single class, but I just
put a Rails app up on Heroku to do something spreadsheet-like, and you
might find my models adaptable. (The UI is unpolished, there isn't
much description or help, and the workflow needs some tweaking, but
basic functionality is ready.) Check out:

  http://thedecider.herokuapp.com

The models are:

- Decisions have a name and a User, and many Factors and Alternatives
- Factors have a name, and a numeric weight, and belong to a Decision
- Alternatives have a name, and belong to a Decision
- Rankings have a Factor, an Alternative, and a numeric level

The purpose is to multiply the levels by the weights and thus decide
on what's the best Alternative.

Similarly, a couple years back I wrote a RoR app for work, in which, IIRC:

- A Sheet had a name, and many Projects and Parts through Ratings
- A Project had a name, and belonged to many Sheets through Ratings
- A Part had a name (meant to be some standard aspect of a project),
and belonged to many Sheets through Ratings
- A Facet had a name, intended to be something like Benefit, Effort, or Risk
- A Rating had a Project, a Part, a Facet, and a Level. The Project
and Part could be nil to indicate an overall rating for the other
item.
- Sheets were displayed with a dropdown list of Facets, including some
pseudo-facets like "Benefit / Risk", "Benefit / Effort", and "Benefit
/ Risk / Effort". If pseudo-facets were displayed, the sheet was
read-only.

The purpose was to let a manager extrapolate and interpolate from
partial decisions about the levels of benefit, risk, or other facets,
of certain projects and their parts, to the whole project, or that
part in general so as to be able to rate other projects, and their
parts. Then he could also divide one sheet by another (or in the case
of B/R/E, two) to find the "low hanging fruit". I've been intending
to reconstruct this thing, with separate user accounts and
authentication, and push it to Heroku. (Max, if you've ever heard the
Tools guys mention BEARPISS, that was this.)

If I wanted to make a generic spreadsheet, just for storage, no
calculation, I think I'd do:

- Sheets have a name, and many Rows and Columns
- Rows and Columns have names, and belong to a Sheet
- Cells have a Row and a Column

Then instead of having each cell-change cause a submission as
TheDecider currently does, have a master Submit button. (I'm thinking
of switching to that since the Alternatives get sorted by total score
so the movement gets confusing.)

-Dave