例如
insert_after :homepage_products do
"
<h1>Promotional Item</h1>
<% products=Product.find_by_sql('select * from products where id in (select product_id from products_taxons where taxon_id in (select id from taxons where name='Promotion'))') %>
<%= render 'shared/products', :products => products, :taxon => @taxon %>
"
end
会给出这个错误
compile error
inline template:3: syntax error, unexpected tCONSTANT, expecting ')'
...m taxons where name='Promotion'))')
^
inline template:3: syntax error, unexpected ')', expecting kEND
...ons where name='Promotion'))')
^
这里的问题是这条线
select * from products where id in (select product_id from products_taxons where taxon_id in (select id from taxons where name='Promotion')
给出语法错误的用法,'
但如果我将其更改为"Promotion"
,它将看起来像这样
insert_after :homepage_products do
"
<h1>Promotional Item</h1>
<% products=Product.find_by_sql('select * from products where id in (select product_id from products_taxons where taxon_id in (select id from taxons where name="Promotion"))') %>
<%= render 'shared/products', :products => products, :taxon => @taxon %>
"
end
注意促销词是如何变成不同颜色的?因为它与前面的重叠"
还有其他可以在这里使用的“特殊字符”吗?
还是有其他选择?