新手问题 rails 的模板系统比较复杂,有没有输入模板代码可以立马看到 html 代码的方法?

kikyous · June 22, 2012 · Last by kikyous replied at June 22, 2012 · 2171 hits

rt

erb 比起 haml,还算直观,同时开着编辑器和 Firefox,用 firebug 看代码

Rails console:

ruby-1.9.3-p0 :025 > $a = "<script>alert(1)</script>here"
 => "<script>alert(1)</script>here" 
ruby-1.9.3-p0 :026 > helper.render :inline => "<%= $a %>"
 => "&lt;script&gt;alert(1)&lt;/script&gt;here" 

注意,这里不能用实例变量,因为真实的模板处理还有一个步骤是把 controller 里的实例变量注入到模板里面。在 console 里只能用全局变量代替了。

又理解错楼主的题意了 -_-|||

You need to Sign in before reply, if you don't have an account, please Sign up first.