【问题标题】:Label references for associations关联的标签引用
【发布时间】:2011-07-18 20:04:27
【问题描述】:

Rails 为固定装置中的关联提供标签引用,如下所示:

### in pirates.yml

  reginald:
    name: Reginald the Pirate
    monkey: george

### in monkeys.yml

  george:
    name: George the Monkey
    pirate: reginald

这对于非命名空间模型非常有效,但我使用的是命名空间,因此 Rails 会感到困惑,并希望插入标签而不是标签引用。

任何已知的解决方法或修复?

【问题讨论】:

    标签: ruby-on-rails-3 testing namespaces integration-testing fixtures


    【解决方案1】:

    Fixtures.identify 似乎是唯一的解决方案,不是很漂亮但比 ids 更好。

    ### in pirates.yml
    
      reginald:
        name: Reginald the Pirate
        monkey_id: <%= Fixtures.identify(:george) %>
    
    
    ### in monkeys.yml
    
      george:
        name: George the Monkey
        pirate_id: <%= Fixtures.identify(:reginald) %>
    

    【讨论】:

    猜你喜欢
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    相关资源
    最近更新 更多