How to define factory girl in rails for model that isn't in root of the models folder?
问题 I would like to create a factory girl for a model in my server which is inside a folder in the models folder. My tree view looks like: ├── app | ├── models │ │ ├── xxx │ │ | ├── user.rb ├── spec │ ├── factories │ │ ├── xxx │ │ | ├── user.rb My factory girl looks like: FactoryGirl.define do factory :user do username { 'aaa' } end end When I try to build user I get the error: undefined method `new' for User:Module 回答1: Is your model defined under a namespace? For example, if your app/models/xxx