Skip to content

Commit 4b0d596

Browse files
committed
extracted method: nested_singular_association?
1 parent 229f7b8 commit 4b0d596

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

frontends/default/views/on_create.js.rjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial
55
if controller.send :successful?
66
if render_parent? && controller.respond_to?(:render_component_into_view)
77
parent_rendered = controller.send(:render_component_into_view, render_parent_options)
8-
if nested? && (nested.belongs_to? || nested.has_one?)
8+
if nested_singular_association?
99
page << "action_link.close('#{escape_javascript(parent_rendered)}');"
1010
else
1111
if render_parent_action == :row

frontends/default/views/on_update.js.rjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial
55
if controller.send :successful?
66
if render_parent? && controller.respond_to?(:render_component_into_view)
77
parent_rendered = controller.send(:render_component_into_view, render_parent_options)
8-
if nested? && (nested.belongs_to? || nested.has_one?)
8+
if nested_singular_association?
99
page << "action_link.close('#{escape_javascript(parent_rendered)}');"
1010
else
1111
if render_parent_action == :row

lib/active_scaffold/helpers/controller_helpers.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module ActiveScaffold
22
module Helpers
33
module ControllerHelpers
44
def self.included(controller)
5-
controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action}
5+
controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?}
66
end
77

88
include ActiveScaffold::Helpers::IdHelpers
@@ -50,12 +50,16 @@ def main_path_to_return
5050
end
5151
end
5252

53+
def nested_singular_association?
54+
nested? && (nested.belongs_to? || nested.has_one?)
55+
end
56+
5357
def render_parent?
54-
(nested? && (nested.belongs_to? || nested.has_one?) || params[:parent_sti])
58+
nested_singular_association? || params[:parent_sti]
5559
end
5660

5761
def render_parent_options
58-
if nested? && (nested.belongs_to? || nested.has_one?)
62+
if nested_singular_association?
5963
{:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}
6064
elsif params[:parent_sti]
6165
options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])}

0 commit comments

Comments
 (0)