Spree hook 的使用仅限于 1 个特殊报价?
例如
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
注意“Promotion”字样如何变成不同的颜色? 因为它与前面的 "
重叠,
这里还有其他可以使用的“特殊字符”吗?
或者有其他选择吗?
for example
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
will give this error
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'))')
^
the problem here is this line
select * from products where id in (select product_id from products_taxons where taxon_id in (select id from taxons where name='Promotion')
the usage of '
giving the syntax error
but if i change it to "Promotion"
, it will look something like this
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
notice how the Promotion words become different colour?
because its overlap with the previous "
is there any other "special character" that can be used here?
or is there any alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在项目中使用的另一种方法是使用备用 Ruby 语法进行引用,例如:
当然,您也可以将代码放入部分代码中,并将部分代码提供给钩子。
还值得一提的是,在最新的 spree 版本中,这hook 系统已被弃用,取而代之的是 deface gem。
An alternate approach that I use in my projects is to use alternate Ruby syntax for quoting, such as:
Of course you can also put your code into a partial and supply the partial to the hook
It's also worth mentioning that in the latest spree versions this hook system is being deprecated in favor of the deface gem.
找到答案
只需输入\
found the answer
just put the \