0
我在app/views/layouts目录中有application.html.erb。Rails布局相关问题
application.html.erb
if @condition
<%= yield %>
end
index.html.erb在app /视图/项目目录
<% @value.id %>
item_controller.rb
def index
@value = nil
if @condition
@value = my_value
end
respond_to do |format|
format.html
end
end
如果@condition是假/localhost:3000/item渲染错误,@value为零。为什么?我没有项目的布局文件,如果@条件是true,它工作正常。
即使application.html.erb不是产量是否检查index.html.erb?
我不需要显示所有的我的源代码:)。无论如何,我想知道为什么index.html.erb渲染时,@条件等于false。请帮助任何人〜 – 2010-06-22 10:54:15
@xopht:看看我编辑的答案,但是如果您需要全面的结果/理解,为什么不发布您的完整代码,您正在尝试执行的步骤,以便我可以在Netbeans中进行调试并让您知道。 – bragboy 2010-06-22 11:44:58
我认为...,因为application.html.erb是视图的一部分,<%= yield %>不会评估条件,只是呈现index.html.erb。因此,我只是将index.html.erb中的整个代码与<%if @condition%> ... <% end %>一起打包。这项工作没关系。其他解决方案? – 2010-06-23 02:11:33