2015-04-06 66 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,它解決了這個問題。