2015-04-06 35 views
0

我有这段代码,我试图从我的视图中调用,但没有成功。传递块给部分帮手

# 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

回答

2

使用此代码

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

解决它,我更换了partial键与layout,它解决了这个问题。