Paper form for database

I am making a Rails 3 application that replaces a paper form for a company. The paper format covers two pages and contains many fields, check boxes, drop-down sheets, etc.

I am wondering how to model this in the database - one approach is to simply create a field in the database for each field in the form (normalized, of course). This will make it difficult to advertise or delete applications, as migration will be necessary. Another approach is to make some kind of key / value store (no - MongoDB / CouchDB is not an option - MySQL is required). Executing a key / value will be very flexible, but it will be painful to request. And will it work directly with ActiveRecord?

Does anyone have a great solution for this?

Hi,

Jacob

+3
source share
2 answers

I would recommend that you model the most common attributes as separate database fields. Once you configure as many fields as possible, return to using the key value setting for your pseudo-random attributes. I would recommend an easy way to store Hashusing the method ActiveRecord serialize. For instance:

class TPS < ActiveRecord::Base
  serialize :custom, Hash
end

@tps = TPS.create(:name => "Kevin", :ssn => "123-456-789", :custom => { :abc => 'ABC', :def => )'DEF' })
@tps.name # Kevin
@tps.ssn  # 123-456-789
@tps.custom[:abc] # ABC
@tps.custom[:def] # DEF
+1
source

If your form is fairly static, go ahead and create a model for it, which is a reasonable approach, even if it seems pretty rudimentary. It is not your fault that the form is so complex, you just come up with a solution that takes this into account. To make adjustments to this, migrations are very simple to implement and easy to understand.

/ , . , , . , , , , , WuFoo, , , .

0

Source: https://habr.com/ru/post/1783488/


All Articles