Zakoff
Zakoff

Reputation: 13005

Is there is 'grid' input form in rails?

I am building a form that is essentially a 5 x 5 grid with the 5 columns being the same as the 5 rows. The grid represents a correlation matrix for 5 items

If I do this as a standard form, I will need to define 25 input names/parameters, for example:

a_corr_with_a a_corr_with_b a_corr_with_c a_corr_with_d . . e_corr_with_e

Is there a quick way to auto generate the grid in rails? For example if my grid was 10 x 10, it would mean I need to manually name 100 elements in my form and this feels inefficient

Upvotes: 1

Views: 355

Answers (1)

Peter Brown
Peter Brown

Reputation: 51717

I doubt Rails has this functionality, but couldn't you do it using a loop within a loop? You could probably create helper that would take care of the logic:

module MatrixHelper
  ROWS = 10
  COLS = 10

  def build_matrix
    # create a table
    ROWS.times do |row|
      # add a row
      COLS.times do |col|
        # add columns
      end
    end
  end
end

Upvotes: 0

Related Questions