Class: ActiveRecord::Base

Inherits:
Object show all
Includes:
Magnetic::Field::DSL
Defined in:
lib/magnetic/rails.rb

Class Method Summary collapse

Methods included from Magnetic::Field::DSL

#field, #field_for, #fieldset, included

Class Method Details

.field_for(name) ⇒ Object



5
6
7
8
# File 'lib/magnetic/rails.rb', line 5

def self.field_for name
  name = name.to_s
  fieldset[name] or generate_default_field_for(name)
end

.generate_default_field_for(name) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
# File 'lib/magnetic/rails.rb', line 10

def self.generate_default_field_for name 
  cname = name.to_s
  m = self
  raise ArgumentError, "no such column <#{ cname }>" unless columns_hash[cname]
  field cname do
    model m
  end
end