简体   繁体   中英

Pass block to partial in helper

I've this code which I'm trying to call from my view, without success.

# 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

This results in this error '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. , why is that?

I'm using Rails 4.0.5 .

Solved it using this code

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

I replaced the partial key with layout , which solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM