2016-02-12 23:52:43 +08:00
|
|
|
class SampleCustomField < ActiveRecord::Base
|
2017-01-05 19:51:14 +08:00
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2016-09-21 21:35:23 +08:00
|
|
|
auto_strip_attributes :value, nullify: false
|
2017-01-05 19:51:14 +08:00
|
|
|
before_validation :sanitize_fields, on: [:create, :update]
|
2016-10-05 23:45:20 +08:00
|
|
|
validates :value,
|
|
|
|
presence: true,
|
|
|
|
length: { maximum: Constants::NAME_MAX_LENGTH }
|
2016-02-12 23:52:43 +08:00
|
|
|
validates :custom_field, :sample, presence: true
|
|
|
|
|
|
|
|
belongs_to :custom_field, inverse_of: :sample_custom_fields
|
|
|
|
belongs_to :sample, inverse_of: :sample_custom_fields
|
2017-01-05 19:51:14 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def sanitize_fields
|
|
|
|
self.value = escape_input(value)
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|