Hi all, Is there a function/method that does the reverse of h() ? I need to decode some html-entities-encoded string back to the actual characters, e.g. "&" to "&", and so on. By the way, I couldn't find the documentation for h() in the Rails API docs, is it not part of Rails? Where should I look for its docs? I thought maybe I could find the reverse function in the docs. Thanks in advance. Cheers, Ronny
on 13.11.2005 02:34
on 13.11.2005 02:46
h() is just an alias for html_escape, but that doesn't seem to be showing up in the docs. Unfortunately I can't tell you how to reverse h()...but it seems like you might be using it wrong (or I'm using it wrong, so I'd like to be corrected!). I was under the impression that it's just used for sanitizing output before it's sent to the browser, so it would be done in a controller or view. It sounds to me like you're calling h() when you insert something into the database, which is unnecessary and you'll end up running into the problems you have. That may not be your particular situation, but it's a comment I have that may help other people avoid misusing h() in this manner. Pat
on 13.11.2005 02:52
Total guess here, but would CGI::unescapeHTML do what you want?
on 13.11.2005 02:58
On Nov 12, 2005, at 8:44 PM, Pat Maddox wrote: > h() is just an alias for html_escape, but that doesn't seem to be > showing up in the docs. > These are in erb and thus don't show up in the Rails API docs.
on 13.11.2005 06:07
On Sat, Nov 12, 2005 at 06:44:43PM -0700, Pat Maddox wrote: > h() is just an alias for html_escape, but that doesn't seem to be > showing up in the docs. Ah, I see. > Unfortunately I can't tell you how to reverse h()...but it seems like > you might be using it wrong (or I'm using it wrong, so I'd like to be > corrected!). I was under the impression that it's just used for > sanitizing output before it's sent to the browser, so it would be done > in a controller or view. You're right. AFAIK, h() is only relevant in the view. I wouldn't use h() in a model or controller. > It sounds to me like you're calling h() when you insert something > into the database, which is unnecessary and you'll end up running > into the problems you have. No, my situation is different actually, and it's a bit complicated (at least for me). I want to do an inline text editing with AJAX (a la Flickr). Maybe I'm not doing it right, or just complicating things. So my asking this is just out of curiosity really. Anyway, I looked in the source code for html_encode() and it's just a one-liner regex substitution, so I can create a helper function that does the reverse if I want to. http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.html#M000688 Thanks to everyone who responded. You've been very helpful. Ronny
on 13.11.2005 06:07
On Sat, Nov 12, 2005 at 08:49:49PM -0500, Andrew Stone wrote:
> Total guess here, but would CGI::unescapeHTML do what you want?
Yes! That would work too. Even more complete than h()/html_escape()
reversed, actually.
Thanks.
Ronny
on 13.11.2005 06:47
On Sun, Nov 13, 2005 at 04:04:53PM +1100, Ronny Haryanto wrote: > Anyway, I looked in the source code for html_encode() and it's just a > one-liner regex substitution, so I can create a helper function that > does the reverse if I want to. > > http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.html#M000688 There's also a Javascript version included with Rails (script.aculo.us actually) if anyone's interested. String.prototype.escapeHTML() String.prototype.unescapeHTML() http://wiki.script.aculo.us/scriptaculous/show/Prototype Ronny
on 13.11.2005 06:50
Why aren't you using the built-in script.aculo.us support that makes inline text editing almost trivial to implement? Check out the fairly well hidden documentation for the method "in_place_editor" on http://rails.rubyonrails.com/
on 13.11.2005 07:23
On Sat, Nov 12, 2005 at 09:48:32PM -0800, Tom Fakes wrote: > Why aren't you using the built-in script.aculo.us support that makes > inline text editing almost trivial to implement? > > Check out the fairly well hidden documentation for the method > "in_place_editor" on http://rails.rubyonrails.com/ D'oh! *slaps head hard* I'm so glad I asked the list. I really learned a lot of new things from this list. I'll definitely look into script.aculo.us more. Thanks, Tom. Ronny
on 13.11.2005 14:35
There is no documentation for "in_place_editor" on http://rails.rubyonrails.com/ It's completely blank. The exact blank page is http://rails.rubyonrails.com/files/vendor/rails/actionpack/lib/action_controller/macros/in _place_editing_rb.html Warren Seltzer
on 13.11.2005 14:53
On Sun, Nov 13, 2005 at 03:34:15PM +0200, Warren Seltzer wrote: > There is no documentation for "in_place_editor" on http://rails.rubyonrails.com/ > It's completely blank. > > The exact blank page is > http://rails.rubyonrails.com/files/vendor/rails/actionpack/lib/action_controller/macros/in > _place_editing_rb.html > > Warren Seltzer I found this page: http://wiki.rubyonrails.com/rails/pages/HowToStyleInPlaceEditorWithCss which brought me here: http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor HTH. Ronny
on 13.11.2005 15:38
Ronny Haryanto wrote: > actually) if anyone's interested. > > String.prototype.escapeHTML() > String.prototype.unescapeHTML() The site seems to be unreachable for me at the moment, so I can't check the docs, but how well do those functions cope with different character sets?
on 13.11.2005 17:55
Did anybody succeeded in using InPlaceEditing inside a partial
collection?
It's working perfectly in a regular template, but the id part becomes
blank when it's inside a partial collection.
article_controller.rb:
class ArticleController < ApplicationController
in_place_edit_for :comment, :body
...
end
_comment.rhtml:
<li id="comment-<%= comment.id %>">
<%= in_place_editor_field :comment, :body %>
</li>
show.rhtml:
....
<ol id="comments">
<% unless @article.comments == nil %>
<%= render :partial => "comment", :collection => @article.comments %>
<% end %>
</ol>
....
Generated HTML:
....
<li id="comment-21">
<span class="in_place_editor_field" id="comment_body__in_place_editor"
tag="span"></span><script type="text/javascript">
//<![CDATA[
new Ajax.InPlaceEditor('comment_body__in_place_editor',
'/article/set_comment_body')
//]]>
</script>
....
[comment_body__in_place_editor] should be
[comment_body_21_in_place_editor].
Apparently, the id is not set properly.
More odd thing is that when a comment is added using AJAX, above code
is working again.
I also tried to include :id as follows:
<%= in_place_editor_field :comment, :body, { :id => comment.id } %>
But in this case, [comment_body__in_place_editor] only becomes [21],
but not [comment_body_21_in_place_editor]
Here are the docs for InPlaceEditing:
http://rails.rubyonrails.com/classes/ActionController/Macros/InPlaceEditing/ClassMethods.html
http://rails.rubyonrails.com/classes/ActionView/Helpers/JavaScriptMacrosHelper.html#M000367
What am I missing here?
--Joon
on 13.11.2005 17:59
alex wrote: > Ronny Haryanto wrote: >> actually) if anyone's interested. >> >> String.prototype.escapeHTML() >> String.prototype.unescapeHTML() > > The site seems to be unreachable for me at the moment, so I can't check > the docs, but how well do those functions cope with different character > sets? These functions won't touch anything except &\"<>.
on 13.11.2005 18:07
Andreas Schwarz wrote: >>the docs, but how well do those functions cope with different character >>sets? > > > These functions won't touch anything except &\"<>. > Excellent. Just what I need.
on 14.11.2005 04:45
The rails.rubyonrails.com site is a frames based one, when I drill down to the docs, the frame URL I get to is this one: http://rails.rubyonrails.com/classes/ActionView/Helpers/JavaScriptMacrosHelp er.html#M000366 I did say it was hard to find :-)
on 04.12.2005 03:23
Speaking of hard to find... Where is the 'h' function defined? Thanks, -Kelly
on 17.12.2005 02:35
railsinator wrote: > Speaking of hard to find... > > Where is the 'h' function defined? > > Thanks, > > -Kelly it's an alias of humanize... look for that :) Jake
on 17.12.2005 07:23
Jacob Stetser wrote: >> >> > >it's an alias of humanize... > >look for that :) > >Jake > > > No. It's an alias for html_escape. See http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.html -- stefan