-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing block to f.label fails in 0.9.4 #24
Comments
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,
|
The problem appears to be that 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 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. |
…yielding helpers' that is referenced by YieldedObjectOutputter to determine when to call wrap_block_as_needed
…yielding helpers' that is referenced by YieldedObjectOutputter to determine when to call wrap_block_as_needed
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 |
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 I'll tackle this shortly and let you know! |
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... |
Just reviewing some code and wanted to chime in -- I'm monkeypatching @karlhe's code from #24 (comment) and it's working great 👍. |
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 |
cc @alexch |
This has been fixed in 0.9.5. Take a look at my comments on PR #37 for more color. :) |
@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.Stacktrace:
The text was updated successfully, but these errors were encountered: