-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
has_one_association.rb
48 lines (38 loc) · 1.2 KB
/
has_one_association.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'rails_admin/config/fields/association'
module RailsAdmin
module Config
module Fields
module Types
class HasOneAssociation < RailsAdmin::Config::Fields::Association
# Register field type for the type loader
RailsAdmin::Config::Fields::Types::register(self)
register_instance_option :partial do
nested_form ? :form_nested_one : :form_filtering_select
end
# Accessor for field's formatted value
register_instance_option :formatted_value do
(o = value) && o.send(associated_model_config.object_label_method)
end
register_instance_option :inline_add do
true
end
register_instance_option :inline_edit do
true
end
def editable?
(nested_form || abstract_model.model.new.respond_to?("#{self.name}_id=")) && super
end
def selected_id
value.try :id
end
def method_name
nested_form ? "#{self.name}_attributes".to_sym : "#{self.name}_id".to_sym
end
def multiple?
false
end
end
end
end
end
end