Module: ActiveScaffold::Helpers::ControllerHelpers
- Includes:
- IdHelpers
- Defined in:
- lib/active_scaffold/helpers/controller_helpers.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from IdHelpers
#action_iframe_id, #action_link_id, #active_scaffold_calculations_id, #active_scaffold_column_header_id, #active_scaffold_content_id, #active_scaffold_id, #active_scaffold_messages_id, #active_scaffold_tbody_id, #association_subform_id, #before_header_id, #controller_id, #element_cell_id, #element_form_id, #element_messages_id, #element_row_id, #empty_message_id, #id_from_controller, #loading_indicator_id, #nested_id, #scope_id, #search_input_id, #sub_form_id, #sub_form_list_id, #sub_section_id
Class Method Details
.included(controller) ⇒ Object
4
5
6
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 4
def self.included(controller)
controller.class_eval { helper_method :params_for, :conditions_from_params, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated, :generate_temporary_id, :generated_id}
end
|
Instance Method Details
#build_associated(column, record) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 89
def build_associated(column, record)
if column.singular_association?
if column.association.options[:through]
record.send(:"build_#{column.association.through_reflection.name}").send(:"build_#{column.name}")
else
record.send(:"build_#{column.name}")
end
else
record.send(column.name).build
end
end
|
#generate_temporary_id(record = nil, generated_id = nil) ⇒ Object
10
11
12
13
14
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 10
def generate_temporary_id(record = nil, generated_id = nil)
(generated_id || (Time.now.to_f*1000).to_i.to_s).tap do |id|
(@temporary_ids ||= {})[record.class.name] = id if record
end
end
|
#generated_id(record) ⇒ Object
16
17
18
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 16
def generated_id(record)
@temporary_ids[record.class.name] if record && @temporary_ids
end
|
#main_path_to_return ⇒ Object
Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 36
def main_path_to_return
if params[:return_to]
params[:return_to]
else
exclude_parameters = [:utf8, :associated_id]
parameters = {}
if params[:parent_scaffold] && nested? && nested.singular_association?
parameters[:controller] = params[:parent_scaffold]
exclude_parameters.concat [nested.param_name, :association, :parent_scaffold]
end
parameters.merge! nested.to_params if nested?
if params[:parent_sti]
parameters[:controller] = params[:parent_sti]
end
parameters[:action] = "index"
parameters[:id] = nil
params_for(parameters).except(*exclude_parameters)
end
end
|
#nested_singular_association? ⇒ Boolean
58
59
60
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 58
def nested_singular_association?
nested? && (nested.belongs_to? || nested.has_one?)
end
|
#params_for(options = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 20
def params_for(options = {})
blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe, :associated_id, :dont_close]
unless @params_for
@params_for = {}
params.except(*blacklist).each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value}
@params_for[:controller] = '/' + @params_for[:controller].to_s unless @params_for[:controller].to_s.first(1) == '/' @params_for.delete(:id) if @params_for[:id].nil?
end
@params_for.merge(options)
end
|
#render_parent? ⇒ Boolean
62
63
64
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 62
def render_parent?
nested_singular_association? || params[:parent_sti]
end
|
#render_parent_action ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 75
def render_parent_action
begin
@parent_action = :row
if params[:parent_sti]
parent_controller = "#{params[:parent_sti].to_s.camelize}Controller".constantize
@parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true
@parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true
@parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true
end
rescue ActiveScaffold::ControllerNotFound
end if @parent_action.nil?
@parent_action
end
|
#render_parent_options ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 66
def render_parent_options
if nested_singular_association?
{:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}
elsif params[:parent_sti]
options = params_for(:controller => params[:parent_sti], :action => render_parent_action, :parent_sti => nil)
options.merge(:id => @record.id) if render_parent_action == :row
end
end
|