1

我一直在阅读一些书籍、博客和开源代码,并且我有一个 Rails 风格指南问题。

使用渲染部分时使用单引号是流行的共识。

<%= render 'posts' %>

或者

<%= render "posts" %>

有些书实际上在他们的编码示例中同时使用了这两种方法。

感谢大家。

4

2 回答 2

2

您可能想在https://github.com/bbatsov/rails-style-guide上查看样式指南的工作,其中使用双引号的原因是指插值原因。

于 2012-06-30T10:41:42.360 回答
1

The only thing to mention here is that single quote strings are slightly more efficient than double qoute strings.

Double quote strings get interpolated:

"Hello #{@name}!"
# => "Hello Chris!"

Single quote strings don't:

'Hello #{@name}!'
# => 'Hello #{@name}!'

This gives single quote strings a slight edge in speed during execution. But don't worry about it too much: The speed gain is really really small.

于 2012-06-30T10:39:07.367 回答