我有它在我的ApplicationControllerRails的AplicationController麻煩
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
$banner = Banner.first
$template = Template.first
end
,並在我的_myfile.html.erb
<%= $template.mainpage_benefits.html_safe %>
我的終端有一個錯誤:
ActionView::Template::Error (undefined method `html_safe' for nil:NilClass
我不t之前($ template = Template.first)遇到了這種做法。請給我解釋一下,我怎麼能解決這個問題
嘗試使用'raw'方法 – uzaif
檢查爲什麼不使用'@ template'而不是'$ template' – uzaif