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  

原文地址:https://www.cnblogs.com/sunada2005/p/3488023.html