Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > What is the difference between the two following pieces of c

Reply
Thread Tools

What is the difference between the two following pieces of c

 
 
Doney Kaka
Guest
Posts: n/a
 
      11-17-2009
Don't really know where to go with this one, but I gotta know...
What is the difference between the two following pieces of code?
Code:
<%= h(truncate(product.description, 80)) %>
and
Code:
<%= truncate(product.description, 80) %>
This question could also be asked by asking what h() does.

http://sieuthi77.com/giavang
http://sieuthi77.com/sangiaodichvang
http://sieuthi77.com/sanvang
http://sieuthi77.com/giaodichvang
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Chris Mowforth
Guest
Posts: n/a
 
      11-17-2009
See the RDoc:

http://ruby-doc.org/stdlib/libdoc/er...l.html#M000305

#h is an alias for #html_escape

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      11-17-2009
Doney Kaka wrote:
> Don't really know where to go with this one, but I gotta know...
> What is the difference between the two following pieces of code?
> Code:
> <%= h(truncate(product.description, 80)) %>
> and
> Code:
> <%= truncate(product.description, 80) %>


Ruby is not Rails, and Rails questions are best asked on a Rails mailing
list.

But briefly: Rails defines a helper method escapeHTML() with alias h().
This escapes HTML, so for example if the product.description is "a<b" it
turns it into "a&lt;b". This is important to prevent users injecting
their own tags and code into the page, as well as ensuring the page
renders properly.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Chris Mowforth
Guest
Posts: n/a
 
      11-17-2009
> Ruby is not Rails, and Rails questions are best asked on a Rails mailing
> list.


I was about to say the same thing but remembered this method can be
found in the standard library. Although in reality I guess rails is the
only context it'll be used in...
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Marnen Laibow-Koser
Guest
Posts: n/a
 
      11-18-2009
Chris Mowforth wrote:
>> Ruby is not Rails, and Rails questions are best asked on a Rails mailing
>> list.

>
> I was about to say the same thing but remembered this method can be
> found in the standard library. Although in reality I guess rails is the
> only context it'll be used in...


Well, Rails is not the only Web framework for Ruby, and anyway, HTML
escaping would be useful in CGI scripts and parsers...

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
http://www.velocityreviews.com/forums/(E-Mail Removed)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Chris Mowforth
Guest
Posts: n/a
 
      11-18-2009
Marnen Laibow-Koser wrote:
> Chris Mowforth wrote:
>>> Ruby is not Rails, and Rails questions are best asked on a Rails mailing
>>> list.

>>
>> I was about to say the same thing but remembered this method can be
>> found in the standard library. Although in reality I guess rails is the
>> only context it'll be used in...

>
> Well, Rails is not the only Web framework for Ruby, and anyway, HTML
> escaping would be useful in CGI scripts and parsers...
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> (E-Mail Removed)


Totally, but let's not start debating that. #candlerb implied that this
was an RoR thing and the question should be posted elsewhere; he should
RTFM.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Marnen Laibow-Koser
Guest
Posts: n/a
 
      11-18-2009
Chris Mowforth wrote:
> Marnen Laibow-Koser wrote:
>> Chris Mowforth wrote:
>>>> Ruby is not Rails, and Rails questions are best asked on a Rails mailing
>>>> list.
>>>
>>> I was about to say the same thing but remembered this method can be
>>> found in the standard library. Although in reality I guess rails is the
>>> only context it'll be used in...

>>
>> Well, Rails is not the only Web framework for Ruby, and anyway, HTML
>> escaping would be useful in CGI scripts and parsers...
>>
>> Best,
>> --
>> Marnen Laibow-Koser
>> http://www.marnen.org
>> (E-Mail Removed)

>
> Totally, but let's not start debating that. #candlerb implied that this
> was an RoR thing and the question should be posted elsewhere; he should
> RTFM.


When you make incorrect statements (like "this will only be used in
Rails"), it's a little funny to tell others to RTFM.


Best,
--
Marnen Laibow-Koser
http://www.marnen.org
(E-Mail Removed)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Chris Mowforth
Guest
Posts: n/a
 
      11-18-2009
> When you make incorrect statements (like "this will only be used in
> Rails"), it's a little funny to tell others to RTFM.
>
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> (E-Mail Removed)



When did I ever explicitly say that? And honestly, who the **** uses it
in anything else? I think it's a fair assertion. Enough with the
pedantry, I'm not replying to this any more. Composers obviously have
the time to pursue these things.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Marnen Laibow-Koser
Guest
Posts: n/a
 
      11-19-2009
Chris Mowforth wrote:
>> When you make incorrect statements (like "this will only be used in
>> Rails"), it's a little funny to tell others to RTFM.
>>
>>
>> Best,
>> --
>> Marnen Laibow-Koser
>> http://www.marnen.org
>> (E-Mail Removed)

>
>
> When did I ever explicitly say that?


You said it quite explicitly in
http://www.ruby-forum.com/topic/199335#868114 : "Although in reality I
guess rails is the only context it'll be used in..."

> And honestly, who the **** uses it
> in anything else?


Anybody dealing with HTML without Rails. Presumably, that includes the
sizable Merb community, among others.

> I think it's a fair assertion.


It might be if Rails were the only popular Ruby Web framework. But
that's not actually the case.

> Enough with the
> pedantry, I'm not replying to this any more.


Probably a good idea.

> Composers obviously have
> the time to pursue these things.


Best,
--
Marnen Laibow-Koser
http://www.marnen.org
(E-Mail Removed)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Josh Cheek
Guest
Posts: n/a
 
      11-19-2009
[Note: parts of this message were removed to make it a legal post.]

Also, http://ruby-toolbox.com/categories/w...rameworks.html lists 6
other Ruby web frameworks. And there are certainly non web application uses
for HTML as well.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between following statements deepak C Programming 25 03-11-2013 02:43 AM
What’s the differences between these two pieces of code ? iMath Python 5 09-09-2012 06:29 PM
Looking for title / artist to two pieces of music Evan Platt Computer Support 1 03-01-2006 06:34 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
algorithm to split number into two pieces Jay C Programming 11 02-25-2004 12:27 AM



Advertisments