ruby-on-rails - Deface,如何向按钮添加类

标签 ruby-on-rails twitter-bootstrap overriding spree

美好的一天。
我想将参数“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

btn button div

最佳答案

通常,当覆盖对我不起作用时,是因为我引用了错误版本的 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/

相关文章:

ruby-on-rails - Ruby 中对象销毁的通知

javascript - 使用 ajax、vanilla javascript 更新 Rails HTML 表

twitter-bootstrap - Bootstrap v4 表单,同一行有 3 个输入 + 按钮

css - 使用 Bootstrap Tour 时禁用突出显示的区域

java - 我如何主要使用其他代码?

ruby-on-rails - Rails3 - 这是性能更好的代码

jquery - 在 jquery token 输入中创建 token

html - 向右浮动使我的专栏变得一团糟

php - 覆盖在 symfony3 中不起作用的翻译器类

javascript - 使用自定义按钮扩展 L.control.zoom