首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Deface,如何向按钮添加类

Deface,如何向按钮添加类
EN

Stack Overflow用户
提问于 2012-07-05 07:20:21
回答 2查看 1.9K关注 0票数 2

日安。

我想把参数'btn btn-primary‘添加到Spree app的一个按钮上。

我也尝试使用Deface来实现这个目标。

但是下面的代码不起作用。

app/overirdes/add_class_btn.rb

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-05 15:39:47

代码语言:javascript
复制
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。

票数 1
EN

Stack Overflow用户

发布于 2012-07-05 08:42:20

通常,当覆盖对我不起作用时,这是因为我引用了错误的Spree版本。例如,我的项目使用的是Spree1.0,但我在github上引用的是1.1,所以我要查找的data-hook名称或文件并不存在。

所以现在,我不再查看github,而是直接查看我的项目正在使用的Spree gem。为此,请使用bundle show spree。您可以像这样转到该目录:

代码语言:javascript
复制
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的虚拟路径:

运行它以验证您的覆盖是否确实引用了某些内容。

代码语言:javascript
复制
rake deface:get_result['spree/products/_cart_form']
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11336313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档