我在处理 draper gem 时遇到了一些问题。
安装 draper gem 'draper'
$ bundle install
这是成功的。
做过
rails generate draper:install
$ rails generate draper:install
但我有一些错误
Expected string default value for '--test-framework'; got false (boolean)
Expected string default value for '--helper'; got true (boolean)
Expected string default value for '--assets'; got true (boolean)
Expected string default value for '--test-framework'; got false (boolean)
Expected string default value for '--helper'; got true (boolean)
Expected string default value for '--decorator'; got true (boolean)
Expected string default value for '--decorator'; got true (boolean)
Expected string default value for '--jbuilder'; got true (boolean)
Could not find generator draper:install.
没关系,我做到了
rails generate decorator Service
Expected string default value for '--test-framework'; got false (boolean) Expected string default value for '--helper'; got true (boolean) Expected string default value for '--assets'; got true (boolean) Expected string default value for '--test-framework'; got false (boolean) Expected string default value for '--helper'; got true (boolean) Expected string default value for '--decorator'; got true (boolean) Expected string default value for '--decorator'; got true (boolean) Expected string default value for '--jbuilder'; got true (boolean) Expected string default value for '--test-framework'; got false (boolean) create app/decorators/service_decorator.rb
这是成功的。
services_decorator 中的方法
class ServiceDecorator < Draper::Decorator delegate_all def hello 'hello' end end
从视图中调用此方法
<%= Service.first.decorate.hello %>
但这是错误的,
Could not infer a decorator for ActiveRecord::Base.
有人可以教我出了什么问题以及如何解决这个问题吗?rails版本是4.1.7,draper版本是2.1.0