我有这个代码,我试图从我的观点中调用,但没有成功。
# app/viwes/admin/index.html.haml
= panel title: "My title" do
%h2 Hello!
# app/helpers/admin/suggestion_helper.rb
module Admin::SuggestionHelper
def panel(locals, &block)
render({partial: "admin/shared/panel"}, locals, &block)
end
end
# app/views/admin/shared/_panel.html.haml
%h1= title
%div= yield
导致此错误'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.
,为什么会这样?
我正在使用Rails 4.0.5
。
答案 0 :(得分:3)
使用此代码解决了它
def panel(locals, &block)
render(layout: "admin/shared/panel", locals: locals, &block)
end
我将partial
键替换为layout
,解决了问题。