日安。
我想把参数'btn btn-primary‘添加到Spree app的一个按钮上。
我也尝试使用Deface来实现这个目标。
但是下面的代码不起作用。
app/overirdes/add_class_btn.rb
Deface::Override.new(:virtual_path => %q{spree/products/_cart_form},
:name => %{add_class_thumbnails_to_products},
:set_attributes => %q{button#add-to-cart-button},
:disabled => false,
:attributes => {:class => 'btn btn-primary'})Spree partial located there https://github.com/spree/spree/blob/master/core/app/views/spree/products/_cart_form.html.erb
结果应该在下面的图片上:
本地主机:3000/products/product1


发布于 2012-07-05 15:39:47
Deface::Override.new(:virtual_path => "spree/products/_cart_form",
:name => 'replace_add_to_cart_button',
:replace => "code[erb-loud]:contains('add-to-cart-button')",
:text => "<%= button_tag :class => 'large primary btn btn-primary', :id => 'add-to-cart-button', :type => :submit do %>",
:original => "<%= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do %>")这将对按钮应用'btn btn-primary‘标记。我不知道为什么我的第一个例子不想要工作。但目标是get。
发布于 2012-07-05 08:42:20
通常,当覆盖对我不起作用时,这是因为我引用了错误的Spree版本。例如,我的项目使用的是Spree1.0,但我在github上引用的是1.1,所以我要查找的data-hook名称或文件并不存在。
所以现在,我不再查看github,而是直接查看我的项目正在使用的Spree gem。为此,请使用bundle show spree。您可以像这样转到该目录:
cd my_spree_project # make sure you're in your spree project
cd `bundle show spree`另一个非常有用的工具是rake deface:get_result。
deface:get_result
-将列出局部或模板的原始内容、已为该文件定义的覆盖以及生成的标注。get_result只接受一个参数,即模板/partial的虚拟路径:
运行它以验证您的覆盖是否确实引用了某些内容。
rake deface:get_result['spree/products/_cart_form']https://stackoverflow.com/questions/11336313
复制相似问题