Ruby on rails 如何使用FactoryGirl创建名为“;方法”;?
如果method和self.method是保留字,如何创建FactoryGirl实例Ruby on rails 如何使用FactoryGirl创建名为“;方法”;?,ruby-on-rails,ruby,factory-bot,Ruby On Rails,Ruby,Factory Bot,如果method和self.method是保留字,如何创建FactoryGirl实例 FactoryGirl.define do factory :payment do method 'paypal' # self.method doesn't work as well amount 12.95 end end 您需要add_attribute方法,但是@user3946015提到的语法似乎不适用于FactoryGirl 4.5.0。相反,请尝试: add_attrib
FactoryGirl.define do
factory :payment do
method 'paypal' # self.method doesn't work as well
amount 12.95
end
end
您需要
add_attribute
方法,但是@user3946015提到的语法似乎不适用于FactoryGirl 4.5.0。相反,请尝试:
add_attribute(:method) { 'paypal' }
刚刚找到一个答案:add_attribute:method,'GET'你能更改该属性的名称吗?任何东西都已经有了一个来自的
方法
方法,替换该方法可能会导致有趣的问题。