Module: ViewMapper::BelongsToAutoCompleteView
- Includes:
- BelongsToParentModels
- Defined in:
- lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#add_model_actions, #field_for, #find_parent_models, #is_model_dependency_action, #model_info_from_param, #parent_models, #validate_parent_models, #virtual_attribute_for, #virtual_attribute_setter_for
Class Method Details
.source_root ⇒ Object
6
7
8
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 6
def self.source_root
File.expand_path(File.dirname(__FILE__) + "/templates")
end
|
Instance Method Details
#auto_complete_for_method(parent_model) ⇒ Object
34
35
36
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 34
def auto_complete_for_method(parent_model)
"auto_complete_for_#{parent_model.name.underscore}_#{field_for(parent_model)}"
end
|
#auto_complete_installed ⇒ Object
61
62
63
64
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 61
def auto_complete_installed
ActionController::Base.methods.include?('auto_complete_for') ||
ActionController::Base.methods.include?(:auto_complete_for)
end
|
#manifest ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 14
def manifest
m = super.edit do |action|
action unless is_model_dependency_action(action) || !valid
end
if valid
m.template(
"view_form.html.erb",
File.join('app/views', controller_class_path, controller_file_name, "_form.html.erb")
)
add_model_actions(m) unless view_only?
parent_models.reverse.each do |parent_model|
m.route :name => 'connect',
:path => auto_complete_for_method(parent_model),
:controller => controller_file_name,
:action => auto_complete_for_method(parent_model)
end
end
m
end
|
#source_roots_for_view ⇒ Object
10
11
12
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 10
def source_roots_for_view
[ BelongsToAutoCompleteView.source_root, File.expand_path(source_root), File.join(self.class.lookup('model').path, 'templates') ]
end
|
#validate ⇒ Object
38
39
40
41
42
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 38
def validate
@valid = validate_auto_complete_installed
@valid &&= super
@valid &&= validate_parent_models
end
|
#validate_auto_complete_installed ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 53
def validate_auto_complete_installed
if !auto_complete_installed
logger.error "The auto_complete plugin does not appear to be installed."
return false
end
true
end
|
#validate_parent_model(parent_model, child_model_name, child_model, check_setter_method = true) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb', line 44
def validate_parent_model(parent_model, child_model_name, child_model, check_setter_method = true)
valid = super
if valid && !parent_model.has_column?(field_for(parent_model))
logger.warning "Model #{parent_model.name} does not have a #{field_for(parent_model)} column."
return false
end
valid
end
|