What is the difference between the two following pieces of c

B

Brian Candler

Doney said:
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.
 
C

Chris Mowforth

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

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...
 
M

Marnen Laibow-Koser

Chris said:
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,
 
C

Chris Mowforth

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

Best,

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.
 
M

Marnen Laibow-Koser

Chris said:
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,
 
C

Chris Mowforth

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


Best,


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.
 
M

Marnen Laibow-Koser

Chris said:
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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top