0

Instead of my _form generating a new row for each new action how can I make it generate a new column?

TABLE #1:

ACTION | RESULT | MONTH    
ACTION | RESULT | MONTH    
ACTION | RESULT | MONTH

TABLE #2:

ACTION | ACTION | ACTION    
RESULT | RESULT | RESULT   
MONTH  | MONTH  | MONTH

Does one make the change in the index or controller or model?

My ultimate goal is to create a dynamic table where the user can see his improvement from month to month regarding his inputted action so for example if his action is "Mile run" then from one month to the next he would add his fastest mile time. I'm having a hard time with this because all the tutorials I've looked at adds new rows, not new rows and new columns.

BONUS TABLE #3:

ACTION | ACTION | ACTION
RESULT | RESULT | RESULT | MONTH (i.e. Jan)
RESULT | RESULT | RESULT | MONTH (i.e. Dec)
RESULT | RESULT | RESULT | MONTH (i.e. Nov)
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
AnthonyGalli.com
  • 2,796
  • 5
  • 31
  • 80
  • http://stackoverflow.com/questions/4493337/design-pattern-to-add-columns-in-database-table-dynamically Have a look at this. – Kaspar Jan 07 '15 at 23:25

1 Answers1

0

Consider this:

foo = [%w[action result month]] * 3
# => [["action", "result", "month"],
#     ["action", "result", "month"],
#     ["action", "result", "month"]]

foo.transpose
# => [["action", "action", "action"],
#     ["result", "result", "result"],
#     ["month", "month", "month"]]

transpose is built-into Ruby's Array class. So, at a minimum, you can do your normal database requests to get the information you want into an array of values, then transpose it and output that how you want.

Does one make the change in the index or controller or model?

I'd probably do it in the controller.

How to get your bonus table is left to you as a bonus question.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303