2011-05-07 67 views
0

例如Spree掛鉤使用限於只有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') 

'使用給語法錯誤 但如果我將其更改爲它會看起來像這樣

 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 

注意促銷字是如何變成不同顏色的? ,因爲它與前面的重疊"

是否有任何其他「特殊字符」,可以在這裏使用?

還是有其他選擇嗎?

回答

0

,我在我的項目中使用的另一種方法是使用備用Ruby的語法報價,如:

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 

當然你也可以把你的代碼放到一個局部區域,並提供局部的鉤子

insert_after :homepage_products, 'shared/hooks/_after_homepage_products' 

還值得一提的是,在最新的狂歡版本中,這個掛鉤系統已被棄用,以支持deface寶石。

0

找到了答案

<% sql_string = "select * from products where id in (select product_id from products_taxons where taxon_id in (select id from taxons where name=\"Promotion\"))" %> 
    <% products=Product.find_by_sql(sql_string) %> 

只是把\