Transient attribute gives "undefined method `name' for false:FalseClass"

488 views
Skip to first unread message

AQ

unread,
May 3, 2012, 1:12:59 PM5/3/12
to factor...@googlegroups.com
The code below work if I substitute the "sub" on the last line with a number say 99.
Why can I not access the transient attribute "sub" when setting this association?
 
 factory :tx_link do
    units 9.99
    
    factory :link_to_sub do
      ignore do
        sub 0
      end
      units { sub }

      giver { |tx| tx.association(:transaction, units: sub) }
    end
  end

Joe Ferris

unread,
May 3, 2012, 1:18:00 PM5/3/12
to factor...@googlegroups.com
You can access other attributes in attribute definitions because the attribute block is defined in the context of an Evaluator proxy, but that only happens for blocks without arguments. You can rewrite the `giver` line there as either of these:

    giver { association(:transaction, units: sub) }

    giver { |tx| tx.association(:transaction, units: tx.sub) }

-Joe
--
Individuals over processes. Interactions over tools. Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training
 
You received this message because you are subscribed to the "factory_girl" mailing list.
To post to this group, send email to factor...@googlegroups.com
To unsubscribe from this group, send email to
factory_girl...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/factory_girl?hl=en

AQ

unread,
May 3, 2012, 3:35:44 PM5/3/12
to factor...@googlegroups.com
Yes both work, many thanks.
Reply all
Reply to author
Forward
0 new messages