rails中的语法

1. erb文件中的语法说明

erb文件中常混合使用Ruby语言和html语言,以下为两种常见的格式

  • <% 写逻辑脚本(Ruby语法) %>
  • <%= 直接输出变量值或运算结果 %>
    require "erb"  
    domains = {...}  
    sqlTemplate = ERB.new %q{  
    <%for organization in domains.keys%>  
        insert into org_domain(Domain, organization) values('<%=domains[organization]%>','<%=organization%>');  
    <%end%>  
    }  
    sqlFile = File.new("./sql.sql", "w")  
    sqlFile.puts sqlTemplate.result  

 

posted @ 2013-12-23 20:00  myLittleGarden  阅读(880)  评论(0编辑  收藏  举报