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

kikyous · 2012年06月22日 · 最后由 kikyous 回复于 2012年06月22日 · 2171 次阅读

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 里只能用全局变量代替了。

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

需要 登录 后方可回复, 如果你还没有账号请 注册新账号