How to save country-specific bank details?
I am currently developing a rails application which should accept country-specific bank account details.
For example:
German Bank Details:
Kontoinhalber: Alice Springs
Kontonummer: 1234567
Bankleitzahl: 111111111
French Bank Details:
Numéro de compte: 0987654
Clé RIB: 123
Code banque: 12345开发者_如何转开发
Code guichet: 1234
How can I save this different formats to the database? Furthermore how can I display different input fields for this?
As you probably do not need to search through these fields, you could use a serialize
d text field in your model.
Set up a definition for every country, maybe as a constant hash:
BANK_ACCOUNT_FIELDS = {
# use array to preserve order
:de => [:account_holder, :account_number, :bank_number],
:fr => [:account_number, :bank_key, :bank_code, :branch_code]
}
With this you can access every field like
lang = @bank_account.lang # use this field to know the country settings
BANK_ACCOUNT_FIELDS[lang].each do |field_name|
@bank_account.data[field_name] = ...
end
For display use partials for each language, for displaying the field names use the I18n module.
精彩评论