将块传递给部分助手

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.,这是为什么?

我正在使用 Rails 4.0.5.

使用此代码解决了它

def panel(locals, &block)
  render(layout: "admin/shared/panel", locals: locals, &block)
end

我用 layout 替换了 partial 键,问题解决了。