[英]Pass block to partial in helper
我已经尝试从我的角度调用此代码,但没有成功。
# 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.
'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.
, 这是为什么?
我正在使用Rails 4.0.5
。
使用此代码解决了
def panel(locals, &block)
render(layout: "admin/shared/panel", locals: locals, &block)
end
我将partial
关键字替换为layout
,从而解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.