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