在使用Ruby on Rails时,我总是使用<%= some_code %>
将Ruby插入到HTML中。我刚刚注意到其他项目有时使用<%= some_code -%>
。在Ruby on Rails中, - %>意味着什么,而%>
7
A
回答
13
<%= some_code - %>最后的减号删除换行符。用于格式化生成的HTML,而<%= some_code%>不。
感谢,Anubhaw
+0
那么从' <%='vs'<%'? – Shawn 2011-09-15 04:22:59
+0
@ShawnSep'='添加输出,'%'不会用于像条件'<% if %>'这样的东西。 – 2014-09-01 20:21:39
4
1
这个答案是错误的:请参阅https://stackoverflow.com/a/25617607/895245。
在Ruby 2.1(不一定与滑轨),则-
移除一个以下换行符作为指出通过Anubhaw:
- 换行符必须是
>
- 没有空格是后的第一个字符删除
- 只删除一个换行
- 你必须通过
'-'
选择使用它
例子:
require 'erb'
ERB.new("<%= 'a' %>\nb").result == "a\nb" or raise
begin ERB.new("<%= 'a' -%>\nb").result; rescue SyntaxError ; else raise; end
ERB.new("<%= 'a' %>\nb" , nil, '-').result == "a\nb" or raise
ERB.new("<%= 'a' -%>\nb" , nil, '-').result == 'ab' or raise
ERB.new("<%= 'a' -%> \nb" , nil, '-').result == "a \nb" or raise
ERB.new("<%= 'a' -%>\n b" , nil, '-').result == 'a b' or raise
ERB.new("<%= 'a' -%>\n\nb", nil, '-').result == "a\nb" or raise
文件:http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/ERB.html
的Rails 4.1的似乎:
相关问题
- 1. >>和>>>在Java中意味着什么?
- 2. (( - >)t)在Haskell中意味着什么?
- 3. - >在PDO PHP中意味着什么?
- 4. “>>>”在java中意味着什么?
- 5. 这是什么意思?这意味着Ruby on Rails?
- 6. “<top(required)>”在Ruby堆栈跟踪中意味着什么?
- 7. <%=h ... %>在Rails中意味着什么?
- 8. <xsd:include schemaLocation =“some.xsd”/>意味着什么
- 9. - >函数原型意味着什么?
- 10. 什么“return $ container - > {$ resource};”意味着
- 11. 这意味着什么“$ var = * $ self - > {class_var};”
- 12. 是什么阵<T?>意味着
- 13. 什么的 - >目标C意味着
- 14. 这在C中意味着什么? AB-> CD-> Func(param)
- 15. “>> =”在Linux内核源代码中意味着什么?
- 16. 是什么;是否意味着在Ruby?
- 17. 什么是((ManifestItem *)manifest-> currentItem()) - > fileContent = currentHtml();意味着在cpp?
- 18. 什么 - >在eachWithIndex中意味着什么?
- 19. 什么标志 - >在spock框架中意味着什么?
- 20. 这个'&'在Ruby中意味着什么?
- 21. 在Ruby中左移意味着什么?
- 22. $$在Ruby中意味着什么?
- 23. $在Ruby中意味着什么?
- 24. redirect_to(@model)在rails中意味着什么?
- 25. Ruby中的@@意味着什么?
- 26. 什么:除了=> {:no_release =>真}意味着Capistrano的DSL
- 27. 什么呢<built-in>,<命令行>意味着
- 28. $是什么?是否意味着在Ruby?
- 29. 〜>在红宝石宝石依赖中意味着什么?
- 30. 这是什么语法意味着----->“!!”在JavaScript中?
超集的问题,所有格式''<% %>修饰了后者:http://stackoverflow.com/questions/7996695/rails-erb-syntax – 2014-09-01 21:09:19
@CiroSantilli:你”重新统治这些 - 好的工作!我选择了http://stackoverflow.com/questions/7996695/what-is-the-difference-between-and-in-erb-in-rails这个也是... – 2014-09-02 04:50:59