Linus Oleander
Linus Oleander

Reputation: 18127

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., why is that?

I'm using Rails 4.0.5.

Upvotes: 0

Views: 914

Answers (1)

Linus Oleander
Linus Oleander

Reputation: 18127

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.

Upvotes: 3

Related Questions