ruby-on-rails - 渲染部分布局不显示任何内容

标签 ruby-on-rails ruby ruby-on-rails-3.1

我正在寻找的效果是为 html 框实现一个可重用的组件。我发现人们似乎在使用类似以下示例的内容,但它对我不起作用。 我有:

# app/views/home/index.html.erb
top
<% render :layout => 'layouts/box' do %>
  <p>Here is some content</p>
<% end %>
bottom

# app/views/layouts/_box.html.erb
inside box
<%= yield %>

我在浏览器上呈现的最终结果是:

top bottom

仍然,我可以在日志中看到:

Processing by HomeController#index as HTML
Rendered layouts/_box.html.erb (0.1ms)
Rendered home/index.html.erb within layouts/application (1.2ms)

所以框布局正在处理中。它只是没有显示任何东西。 有什么想法吗?

我正在使用 Rails 3.1.3 和 Ruby 1.9.2-p290。

最佳答案

您忘记输出“渲染”调用:

<%= render ... %>

代替

<% render ... %>

关于ruby-on-rails - 渲染部分布局不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8255443/

相关文章:

ruby-on-rails - I18n.locale 的 kaminari page_entires_info 错误

javascript - Rails 自定义布局 - 生产中的路由错误

ruby - 变量改变值, ruby

ruby-on-rails - 如何使用 Nokogiri 解析 HTML 表格?

Ruby - 处理传入的 HTTP POST?

ruby-on-rails - Rails 3.1 + Heroku : Can someone help me decipher this Heroku log?

ruby-on-rails - Controller 规范 + 布料器

ruby-on-rails - Rails 4 : Font Awesome working locally, 在 Heroku 上中断

ruby-on-rails - ruby rails : How do I get the Model name from inside the Controller?

ruby-on-rails - 如何从数据库中选择*,其中列!= Rails 中的值