Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

partial rendering a block with layout and collection does not work #13354

Closed
bughit opened this Issue Dec 17, 2013 · 8 comments

Comments

Projects
None yet
3 participants
Contributor

bughit commented Dec 17, 2013

http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html

the docs are not perfectly clear on this, but it's reasonable to infer that since render layout: 'layout', &block works then render layout: 'layout', collection: collection, &block would work as well.

but collection_with_template completely ignores the @block member that was passwed to render:

    def collection_with_template
      view, locals, template = @view, @locals, @template
      as, counter = @variable, @variable_counter

      if layout = @options[:layout]
        layout = find_template(layout, @template_keys)
      end

      index = -1
      @collection.map do |object|
        locals[as]      = object
        locals[counter] = (index += 1)

        content = template.render(view, locals)
        content = layout.render(view, locals) { content } if layout
        content
      end
    end
Owner

rafaelfranca commented Dec 17, 2013

I think it ignores the block because it is defining the new block. Could you investigate it?

Contributor

bughit commented Dec 17, 2013

I don't see it defining a new block. It stores the passed block in @block and ignores it. You can see render_partial utilizing the block:

    def render_partial
      view, locals, block = @view, @locals, @block
      object, as = @object, @variable

      if !block && (layout = @options[:layout])
        layout = find_template(layout.to_s, @template_keys)
      end

      object ||= locals[as]
      locals[as] = object

      content = @template.render(view, locals) do |*name|
        view._layout_for(*name, &block)
      end

      content = layout.render(view, locals){ content } if layout
      content
    end

but collection_with_template ignores it.

Owner

rafaelfranca commented Dec 17, 2013

I see. Now that you know how to fix, do you want to open a PR? 😄

Contributor

bughit commented Dec 17, 2013

I probably will, not immediately, busy

Owner

rafaelfranca commented Dec 17, 2013

No problem, I can't do right now too but maybe someone else can do.

Contributor

bughit commented Dec 23, 2013

@rafaelfranca, is it good to merge?

@bughit bughit added the stale label Apr 23, 2014

Owner

rafaelfranca commented May 1, 2014

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

This issue has been automatically closed because of inactivity.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

@rails-bot rails-bot closed this May 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment