美好的一天。
我想将参数“btn btn-primary”添加到 Spree 应用程序中的按钮。
我也尝试使用 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 部分位于那里https://github.com/spree/spree/blob/master/core/app/views/spree/products/_cart_form.html.erb
结果应如下图所示:
本地主机:3000/产品/产品1
最佳答案
通常,当覆盖对我不起作用时,是因为我引用了错误版本的 Spree。例如,我的项目使用的是 spree 1.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 - Will list the original contents of a partial or template, the overrides that have been defined for a that file, and the resulting markup. get_result takes a single argument which is the virtual path of the template / partial:
运行它来验证您的覆盖是否确实引用了某些内容。
rake deface:get_result['spree/products/_cart_form']
关于ruby-on-rails - Deface,如何向按钮添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11336313/