Skip to content

Instantly share code, notes, and snippets.

@vsizov
Last active December 22, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsizov/6411954 to your computer and use it in GitHub Desktop.
Save vsizov/6411954 to your computer and use it in GitHub Desktop.
class UsersField < ActiveRecord::Base
belongs_to :user
belongs_to :field
has_one :fields_group, through: :field
validates :value, allow_blank: true
def create_record
if !self.field.required & self.value.blank?
return nil
else
super
end
end
# # Creates a record with values matching those of the instance attributes
# # and returns its id.
# def create_record(attribute_names = @attributes.keys)
# attributes_values = arel_attributes_with_values_for_create(attribute_names)
# new_id = self.class.unscoped.insert attributes_values
# self.id ||= new_id if self.class.primary_key
# @new_record = false
# id
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment