Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for actionview parent layout bug #19685

Merged
merged 1 commit into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions actionview/lib/action_view/layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,25 @@ def _write_layout_method # :nodoc:
name_clause
end

self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout
if _conditional_layout?
if self._layout_conditions.empty?
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout
#{layout_definition}
else
#{name_clause}
end
end
private :_layout
RUBY
private :_layout
RUBY
else
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout
if _conditional_layout?
#{layout_definition}
else
#{name_clause}
end
end
private :_layout
RUBY
end
end

private
Expand Down
14 changes: 14 additions & 0 deletions actionview/test/actionpack/controller/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def hello
end
end

class ParentController < LayoutTest
layout 'item'
end

class ChildController < ParentController
layout 'layout_test', only: :hello
end

class OnlyLayoutController < LayoutTest
layout 'item', :only => "hello"
end
Expand Down Expand Up @@ -225,6 +233,12 @@ def test_absolute_pathed_layout
get :hello
assert_equal "layout_test.erb hello.erb", @response.body.strip
end

def test_respect_to_parent_layout
@controller = ChildController.new
get :goodbye
assert_template :layout => "layouts/item"
end
end

class SetsNonExistentLayoutFile < LayoutTest
Expand Down