Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

link_to_function and fields_for inside block - empty array in with_output_buffer error

#5179

In Rails 3 beta 4:

def add_link(form_builder)
  link_to_function 'add' do |page|
    form_builder.fields_for :task, Task.new do |f|
      ...
    end
  end
end

causes

undefined method `encoding' for []:Array
actionpack (3.0.0.beta4) lib/action_view/helpers/capture_helper.rb:171:in `with_output_buffer'

Reported by Vincent · July 22nd, 2010 @ 05:56 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • Importance changed from to Low

    Can you try it with master and try to do a test case? if not can you please upload an app with this code to make it easier for me to reproduce?.
    Thanks.

    July 22nd, 2010 @ 03:52 PM

  2. Vincent
    Vincent

    I tried with master last night. I will upload an app later tonight.

    Thanks.

    July 22nd, 2010 @ 04:24 PM

  3. Vincent
    Vincent

    Here is the app. The erroneous code is in app/helpers/projects_helper.rb

    July 23rd, 2010 @ 05:17 AM

  4. Santiago Pastorino
    Santiago Pastorino

    Vincent i've tried with the latest code from master and works ok.
    Please try it again with the code from master and let me know.

    July 23rd, 2010 @ 07:25 AM

  5. rorra
    rorra

    I've tried with the latest code from master and ruby 1.9.2 RC 2 and it gives me the same error

    July 24th, 2010 @ 10:03 PM

  6. rorra
    rorra

    Ok, I got a way to reproduce the error in an easy way

    link_to_function("Greet me!") do |page|
      content_tag :h1 do
        'Hi'
      end
    end
    

    July 24th, 2010 @ 11:36 PM

  7. Sebastian A. Espindola
    Sebastian A. Espindola

    I think I fixed the issue.
    I made a modification on line 168 of capture_helper.rb to make sure that
    output_helper responds to the encoding method before using it.
    I've used Rorra's test case, and it passes fine.
    I'm appending a patch.

    July 25th, 2010 @ 07:59 AM

  8. Santiago Pastorino
    Santiago Pastorino
    • Assigned user set to José Valim
    • State changed from new to verified
    • Milestone cleared.

    rorra yeah confirmed, i was testing with 1.8.7 sorry. I see the issue happens on 1.9.2.
    The solution of Sebastian is right for me.

    July 25th, 2010 @ 09:55 AM

  9. Sebastian A. Espindola
    Sebastian A. Espindola

    Right. This problem would only happen on 1.9.x, since now a string
    is a collection of encoded data.
    No other String implementations (AFAIK) respond to the encoding or force_encoding methods.

    July 25th, 2010 @ 03:27 PM

  10. Repository
  11. Carlos Antonio da Silva
    Carlos Antonio da Silva

    I added a new patch updating the test added by this patch, asserting the content generated for link_to_function is ok. The current test has no assertion.

    July 25th, 2010 @ 09:33 PM

  12. Repository
    Repository
    • State changed from verified to resolved

    (from [751f89b8b28634cb237d1e47f33ddefaa13829dc]) Add assertion to link_to_function test with block and capture, and more expressive test name [#5179 link_to_function and fields_for inside block - empty array in with_output_buf... state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/751f89b8b28634cb237d1e47f33dde...

    July 25th, 2010 @ 10:00 PM

  13. rorra
    rorra

    Hey guys, when I first added the test patch to reproduce the error, it was just an ugly example, I didn't thought it was going to be committed into rails :P

    Anyway, the current test doesn't put anything in the onclick attribute, and the

    tag doesn't appears at all.

    I just updated the test to actually expect a valid piece of js code in the onclick attribute

    Thank you

    July 27th, 2010 @ 07:55 PM

  14. rorra
    rorra

    I wanted to say that the

    <h1> tag doesn't appears at all
    

    :)

    July 27th, 2010 @ 08:29 PM

  15. Repository
  16. Jeremy Kemper