Rails fabricator - how to get value from association field? -
Rails fabricator - how to get value from association field? -
let's have model user has many notes. each note has field user_name. notes fabricator this:
fabricator(:note, class_name: note) user content faker::lorem.paragraph(1) user_name user.full_name end
what i'm trying set user_name value full_name method user exists. i'm getting next error:
undefined method `full_name' #<fabrication::schematic::attribute:0x0000000a279c50>
any help appreciated.
found out in documentation there attributes hash can use:
fabricator(:note, class_name: note) user content faker::lorem.paragraph(1) user_name { |attrs| attrs[:user].full_name } end
ruby-on-rails ruby-on-rails-4 fabrication-gem
Comments
Post a Comment