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

problem with yield in layout #47

Closed
senid231 opened this issue Oct 24, 2015 · 2 comments
Closed

problem with yield in layout #47

senid231 opened this issue Oct 24, 2015 · 2 comments

Comments

@senid231
Copy link

i create controller app/controllers/test_controller.rb

class TestController < ApplicationController
  layout 'application'
  def index
  end
end

replace layout app/viewslayouts/application.html.arb

html do
  head do
    title 'Test'
    text_node (stylesheet_link_tag    'application', 'data-turbolinks-track' => true, media: 'all')
    javascript_include_tag 'application', 'data-turbolinks-track' => true
    text_node csrf_meta_tags
  end

  body do
    para 'before content'
    yield
    para 'after content'
  end
end

and add template app/views/test/index.html.arb

h1 'index'

but when i load page it generates output body like:

<body>
    <p>before content</p>
    <p>after content</p>
</body>

but when i change app/viewslayouts/application.html.arb like

html do
  head do
    title 'AdminLTE Arbre'
    text_node (stylesheet_link_tag 'application', 'data-turbolinks-track' => true, media: 'all')
    javascript_include_tag 'application', 'data-turbolinks-track' => true
    text_node csrf_meta_tags
  end

  body do
    para 'before content'
    div { yield }
    para 'after content'
  end
end

yield works correct

<body>
    <p>before content</p>
    <div>
        <h1>index</h1>
    </div>
    <p>after content</p>
</body>

there is no such problem with erb templates

@timoschilling
Copy link
Member

Thats not a bug, that can't be solved in a different way. It's the same in a Erb or Haml Template where you need to place a = yield oder <%= yield %> to capture the output.
You can use this, if you don't want the wrapping div:

text_node yield

@senid231
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants