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, #search_input_id, #sub_form_id, #sub_form_list_id, #sub_section_id, #table_action_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, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?}
end
|
Instance Method Details
#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)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 26
def main_path_to_return
if params[:return_to]
params[:return_to]
else
parameters = {}
if params[:parent_controller]
parameters[:controller] = params[:parent_controller]
parameters[:eid] = params[:parent_controller]
end
if nested?
parameters[:controller] = nested.parent_scaffold.controller_path
parameters[:eid] = nil
end
if params[:parent_sti]
parameters[:controller] = params[:parent_sti]
parameters[:eid] = nil
end
parameters[:parent_column] = nil
parameters[:parent_id] = nil
parameters[:action] = "index"
parameters[:id] = nil
parameters[:associated_id] = nil
parameters[:utf8] = nil
params_for(parameters)
end
end
|
#nested_singular_association? ⇒ Boolean
53
54
55
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 53
def nested_singular_association?
nested? && (nested.belongs_to? || nested.has_one?)
end
|
#params_for(options = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 10
def params_for(options = {})
blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe]
unless @params_for
@params_for = {}
params.select { |key, value| blacklist.exclude? key.to_sym if key }.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
57
58
59
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 57
def render_parent?
nested_singular_association? || params[:parent_sti]
end
|
#render_parent_action(controller_path = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 74
def render_parent_action(controller_path = nil)
begin
@parent_action = :row
parent_controller = "#{controller_path.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
rescue ActiveScaffold::ControllerNotFound
end if @parent_action.nil?
@parent_action
end
|
#render_parent_options ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/active_scaffold/helpers/controller_helpers.rb', line 61
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 = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])}
if render_parent_action(params[:parent_sti]) == :index
options.merge(params.slice(:eid))
else
options.merge({:id => @record.id})
end
end
end
|