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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 11/12/05, Ronny Haryanto <ronnylist-fjQGkq+J5uxhl2p70BpVqQ@public.gmane.org> wrote:> 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 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
Total guess here, but would CGI::unescapeHTML do what you want? -- Andrew Stone _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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. -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com http://rubyi.st
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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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#M000688There''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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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/ -----Original Message----- From: Ronny Haryanto [mailto:ronnylist-fjQGkq+J5uxhl2p70BpVqQ@public.gmane.org] Sent: Saturday, November 12, 2005 9:05 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] reverse of h() 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 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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ronny Haryanto Sent: Sunday, November 13, 2005 8:22 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] reverse of h() 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 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 SeltzerI 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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Ronny Haryanto wrote:> 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()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? -- Alex
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 11/13/05, Tom Fakes <tom-3mLyhfhPcFMAvxtiuMwx3w@public.gmane.org> 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/ > > > -----Original Message----- > From: Ronny Haryanto [mailto:ronnylist-fjQGkq+J5uxhl2p70BpVqQ@public.gmane.org] > Sent: Saturday, November 12, 2005 9:05 PM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails] reverse of h() > > 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 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 &\"<>. -- Posted via http://www.ruby-forum.com/.
Andreas Schwarz wrote:> 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 &\"<>. >Excellent. Just what I need. -- Alex
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 :-) -----Original Message----- From: Warren Seltzer [mailto:warrens-uf+uqdaZT6qTt3WsUyM9gg@public.gmane.org] Sent: Sunday, November 13, 2005 5:34 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails] reverse of h() 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_contro ller/macros/in _place_editing_rb.html Warren Seltzer -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ronny Haryanto Sent: Sunday, November 13, 2005 8:22 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] reverse of h() 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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Speaking of hard to find... Where is the ''h'' function defined? Thanks, -Kelly On 11/13/05, Tom Fakes <tom-3mLyhfhPcFMAvxtiuMwx3w@public.gmane.org> wrote:> > 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 :-) > > > -----Original Message----- > From: Warren Seltzer [mailto:warrens-uf+uqdaZT6qTt3WsUyM9gg@public.gmane.org] > Sent: Sunday, November 13, 2005 5:34 AM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: RE: [Rails] reverse of h() > > 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_contro > ller/macros/in > _place_editing_rb.html > > Warren Seltzer > > > -----Original Message----- > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On > Behalf Of Ronny Haryanto > Sent: Sunday, November 13, 2005 8:22 AM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails] reverse of h() > > > 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 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
railsinator wrote:> Speaking of hard to find... > > Where is the ''h'' function defined? > > Thanks, > > -Kellyit''s an alias of humanize... look for that :) Jake -- Posted via http://www.ruby-forum.com/.
Jacob Stetser wrote:>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 > > >No. It''s an alias for html_escape. See http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB/Util.html -- stefan