Hi! I wanted to mention an odd Erector/Rails issue. We worked around it, but I wanted it documented in case it crops up for somebody else. I couldn't see a quick fix, but perhaps this might inform a refactoring from somebody who knows the code better than I do.
We were outputting user comments. We wanted to do all the things that you normally do with them: prevent evil HTML, auto-link URLs, and turn email addresses into mailtos. But we wanted to shorten the link display text under certain conditions. The total hack settled upon was to abuse the Rails built-in stuff, so we ended up with this line:
parser = Nokogiri::HTML.parse simple_format(auto_link(h(text)))
We'd then go on from there to mutate the parsed tree and then output it as text. Converting to Erector introduced a weird bug. if you commented
what appeared on the page was
contact for help
The problem, it turned out, was that Erector intercepts mail_to, which Rails calls internally as part of auto_link. As part of the intercept, it outputs the linked address immediately and returns nothing. That's the first line. Then our code finishes and returns the comment sans the email address, which gets output as the second line.
Our solution was to extract a CommentFormatter object that pulls in the Rails stuff separately and then call that from our widgets. That way Erector won't intercept anything. Which was probably what we should have done initially anyhow.
William