Rails 4.2 覆盖视图。 Deface 真的是独立的吗?
Rails 4.2 overriding views. Is Deface really standalone?
我正在尝试使用 Deface 覆盖视图。
在手动创作者中称它为独立的,所以我想可以使用这个 gem 而无需使用 spree...但我不确定了,因为我发现几乎每个 tutorial/question/anything污损与狂欢有关。
不过我试过了。我所做的是在 Gemfile
中添加一行
gem 'deface'
和运行
bundle install
肯定安装了污损 gem。
然后我做了这样的路线:
get 'test', to: 'test#show'
空控制器app/controllers/test_controller.rb
class TestController < ApplicationController
def show
end
end
并像这样查看 app/views/test/show.html/erb
<h1 id="test">test first</h1>
然后我转到 cd app
并创建目录覆盖 mkdir overrides
并创建 app/overriders/test_uploader.rb
其中包含:
Deface.Override.new(
:virtual_path => 'test/show',
:name => 'test uploader',
:replace => 'h1#test',
:text => '<h1 id="test">replaced, test passed</h1>'
)
但即使我重新加载服务器也没有任何反应。
为什么?我错过了什么吗?或者也许我真的需要大礼包才能使用 Deface?
不确定为什么您的代码示例不起作用,但我也为您做了简单的示例并且效果很好。您可以在此处下载代码项目 https://github.com/nezirz/deface_gem
还有截图:
我正在尝试使用 Deface 覆盖视图。
在手动创作者中称它为独立的,所以我想可以使用这个 gem 而无需使用 spree...但我不确定了,因为我发现几乎每个 tutorial/question/anything污损与狂欢有关。
不过我试过了。我所做的是在 Gemfile
中添加一行gem 'deface'
和运行
bundle install
肯定安装了污损 gem。
然后我做了这样的路线:
get 'test', to: 'test#show'
空控制器app/controllers/test_controller.rb
class TestController < ApplicationController
def show
end
end
并像这样查看 app/views/test/show.html/erb
<h1 id="test">test first</h1>
然后我转到 cd app
并创建目录覆盖 mkdir overrides
并创建 app/overriders/test_uploader.rb
其中包含:
Deface.Override.new(
:virtual_path => 'test/show',
:name => 'test uploader',
:replace => 'h1#test',
:text => '<h1 id="test">replaced, test passed</h1>'
)
但即使我重新加载服务器也没有任何反应。 为什么?我错过了什么吗?或者也许我真的需要大礼包才能使用 Deface?
不确定为什么您的代码示例不起作用,但我也为您做了简单的示例并且效果很好。您可以在此处下载代码项目 https://github.com/nezirz/deface_gem
还有截图: