lib目錄中,我很新的Rails的,和我努力學習/lib/
目錄Rails中是如何工作的 - 以及如何引用在/lib/
目錄視圖中使用定義的變量。學習關於Rails中
我有一個名爲helloworld.rb
文件,它保存在導軌上的/ lib /目錄。
的helloworld.rb
文件有以下代碼:
module HelloWorld
def hello
@howdy = "Hello World!"
end
end
我希望能夠顯示這些方法的一種稱爲index.html.erb
視圖的結果,所以包括在index_helper.rb
文件以下代碼:
module IndexHelper
require 'helloworld'
end
另外,我包括在視圖index.html.erb
以下代碼:
<%= @howdy %>
我錯過了什麼?
我必須缺少一些東西......當我在我的控制器中實現這個時,我得到以下錯誤:Helloworld的undefined方法'hello':模塊 – 2scottish
...固定後,抱歉! – RadBrad
嗯......我仍然在做錯事,因爲我得到了同樣的錯誤信息。錯誤消息指向控制器中引用'Helloworld :: hello'的行。 另外,我是否正確地假設,在視圖中,我可以通過使用:'<%= setup_hello%>'來引用此代碼? – 2scottish