Giter Club home page Giter Club logo

Comments (9)

ageweke avatar ageweke commented on September 3, 2024

Harlan,

Thanks for the bug report!

I suspect you're exactly right. Unfortunately, I can't easily verify this right now, because I'm in the middle of hiking the Pacific Crest Trail this year, and all I have with me is my iPhone.

I can tell you that the bug almost certainly lies within the YieldedObjectOutputter (https://github.com/ageweke/fortitude/blob/master/lib/fortitude/rails/yielded_object_outputter.rb). When using Rails' form helpers, Fortitude wraps the returned object (the "f" in the code below) in one of these, which is what causes expressions like "f.label" to actually produce HTML output, rather than just returning it. (As you probably know, in ERb, you have to say <%= f.label … %>, which would translate to Fortitude/Erector code like "rawtext f.label …", which is not really what anyone wants to write. For most Rails helpers, Fortitude's helper declarations use :transform => :output_return_value (exact symbol name may vary) to take care of this, but obviously the form helpers are more complex since they're methods on a different object.)

The YieldedObjectOutputter isn't very long. If you can find and fix the bug with a spec, I'll happily accept the pull request. Otherwise, I'm happy to tackle it when I get back in October (or if I'm in a trail town and have success SSHing from my iPhone into my AWS server and making it work from there).

Sorry I can't just hand you a fix right now…but hope this helps point you in the right direction!

Cheers,
Andrew

On Apr 23, 2015, at 11:24 AM, Harlan T Wood [email protected] wrote:

@alexch and I discovered that the following code works as expected in fortitude 0.9.3 but fails in 0.9.4. Seems something gets confused when you pass f.label both args and a block.

form_for(some_obj, url: some_path(some_obj)) { |f|
...
f.label(field_name, value: answer_key) { text answer_text }
Stacktrace:

 ActionView::Template::Error:
   wrong number of arguments (0 for 1+)
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/yielded_object_outputter.rb:8:in `block in wrap_block_as_needed'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:38:in `capture'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/tags/label.rb:36:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/form_helper.rb:750:in `label'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/form_helper.rb:1585:in `label'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/yielded_object_outputter.rb:33:in `method_missing'
 # ./app/views/histories/edit.html.rb:76:in `block (3 levels) in history_choice'
 # (eval):32:in `tag_div'
 # ./app/views/histories/edit.html.rb:75:in `block (2 levels) in history_choice'
 # ./app/views/histories/edit.html.rb:68:in `each'
 # ./app/views/histories/edit.html.rb:68:in `block in history_choice'
 # (eval):12:in `tag_fieldset'
 # ./app/views/histories/edit.html.rb:65:in `history_choice'
 # ./app/views/histories/edit.html.rb:18:in `block (2 levels) in content'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/yielded_object_outputter.rb:10:in `call'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/yielded_object_outputter.rb:10:in `block in wrap_block_as_needed'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:38:in `capture'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/form_helper.rb:434:in `form_for'
 # (eval):3:in `form_for'
 # ./app/views/histories/edit.html.rb:12:in `block in content'
 # (eval):32:in `tag_div'
 # ./app/views/histories/edit.html.rb:11:in `content'
 # (eval):3:in `run_content'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/widget/rendering.rb:35:in `block in render_to'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rendering_context.rb:79:in `record_widget'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/widget/rendering.rb:33:in `render_to'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/renderer.rb:38:in `block (2 levels) in render'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rendering_context.rb:183:in `with_yield_block'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/renderer.rb:37:in `block in render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/renderer.rb:28:in `render'
 # ./app/views/histories/edit.html.rb:1:in `_app_views_histories_edit_html_rb__2472174839435550605_70144171257780'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/template.rb:145:in `block in render'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications.rb:159:in `block in instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications.rb:159:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/template.rb:339:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/template.rb:143:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications.rb:159:in `block in instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications.rb:159:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/template_renderer.rb:53:in `render_template'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/template_renderer.rb:17:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/renderer.rb:42:in `render_template'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/renderer/renderer.rb:23:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/rendering.rb:99:in `_render_template'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/streaming.rb:217:in `_render_template'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/rendering.rb:82:in `render_to_body'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/abstract_controller/rendering.rb:25:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/rendering.rb:16:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/core_ext/benchmark.rb:12:in `ms'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
 # ~/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.10/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/instrumentation.rb:43:in `render'
 # ~/.rvm/gems/ruby-2.1.4/gems/fortitude-0.9.4/lib/fortitude/rails/rendering_methods.rb:85:in `render_with_fortitude'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/abstract_controller/base.rb:189:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/rendering.rb:10:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:113:in `call'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:113:in `call'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:502:in `call'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:502:in `call'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/callbacks.rb:86:in `run_callbacks'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/abstract_controller/callbacks.rb:19:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/rescue.rb:29:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications.rb:159:in `block in instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.10/lib/active_support/notifications.rb:159:in `instrument'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.10/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/abstract_controller/base.rb:136:in `process'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionview-4.1.10/lib/action_view/rendering.rb:30:in `process'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/test_case.rb:595:in `process'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/test_case.rb:64:in `process'
 # ~/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.10/lib/action_controller/test_case.rb:495:in `get'
 # ./spec/controllers/histories_controller_spec.rb:18:in `block (3 levels) in <top (required)>'


Reply to this email directly or view it on GitHub.

from fortitude.

karlhe avatar karlhe commented on September 3, 2024

The problem appears to be that method_missing in YieldedObjectOutputter is wrapping things unnecessarily. Because when wrap_block_as_needed is called from method_missing it passes in the method_names to the child block, the child block is treated as if it had yielded_methods_to_output set which causes issues.

The simple/hack solution would be to just change method_missing to be like this:

      def method_missing(method_name, *args, &block)
        if @method_names_hash[method_name.to_sym]
          if [:form_for, :fields_for].include?(method_name.to_sym)
            block = ::Fortitude::Rails::YieldedObjectOutputter.wrap_block_as_needed(@output_target, method_name, block, @method_names_hash.keys)
          end
          return_value = @yielded_object.send(method_name, *args, &block)
          @output_target.rawtext(return_value)
          EMPTY_RETURN_VALUE
        else
          @yielded_object.send(method_name, *args, &block)
        end
      end

The better solution would probably be to register a list of Rails helpers that provide their own yielded_methods_to_output in Fortitude::Rails::Helpers, then reference that list to see if the child block should be wrapped.

Can't make a proper pull request because I can't figure out how to get the oop rail server to work correctly, but I've fixed it on my fork.

from fortitude.

karlhe avatar karlhe commented on September 3, 2024

Upon some further thought it might be simpler to just check if the block accepts any arguments:

if block && block.arity > 0
  block = ::Fortitude::Rails::YieldedObjectOutputter.wrap_block_as_needed(@output_target, method_name, block, @method_names_hash.keys)
end

from fortitude.

ageweke avatar ageweke commented on September 3, 2024

Karl — as I mentioned in my other reply, I'm back from hiking the PCT. I'll take a look at this issue soon. The YieldedObjectOutputter definitely could stand a little refinement and improvement, and this issue is a great case why.

I'll tackle this shortly and let you know!

from fortitude.

karlhe avatar karlhe commented on September 3, 2024

Welcome back!

It's been a while since I was looking into it, but let me know if there's something I can help with.

I vaguely remember it being more than just this 1 case, but maybe only cause I tried to hack in formtastic support...

from fortitude.

ajb avatar ajb commented on September 3, 2024

Just reviewing some code and wanted to chime in -- I'm monkeypatching @karlhe's code from #24 (comment) and it's working great 👍.

from fortitude.

ajb avatar ajb commented on September 3, 2024

I just submitted PR #37 with a test case for this issue, but here's the thing: the tests are passing, not failing.

@harlantwood / @karlhe: mind taking a look? #37

from fortitude.

harlantwood avatar harlantwood commented on September 3, 2024

cc @alexch

from fortitude.

ageweke avatar ageweke commented on September 3, 2024

This has been fixed in 0.9.5. Take a look at my comments on PR #37 for more color. :)

from fortitude.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.