0

I'm having problems with my fixtures in Rails.

I have two models, a message and a user. The user model is generated from restful authentication. A message has a sender and a recipient, which are both users.

When I don't use the fixtures everything works fine. But when I try to use them in fixtures both are nil.

This is the messages fixtures file:

first_message_for_quentin:
    title: First message
    body: This is your first message.
    recipient: quentin
    sender: aaron

quentin and aaron are the user fixtures which were generated by restful authentication.

Is there a way I can use the generated ids there or do I have to do it another way?

4

2 回答 2

3

Fixtures.identifyActiveRecord Fixtures 通过调用您在 yaml 中为行指定的标签为每一行创建 ID 列。

因此,您应该能够执行以下操作:

first_message_for_quentin:
    title: First message
    body: This is your first message.
    recipient_id: <%= Fixtures.identify(:quentin) %>
    sender_id: <%= Fixtures.identify(:aaron) %>

您可能想查看一些有关夹具标签插值的文档

于 2009-08-06T21:43:44.570 回答
0

问题出在由 RESTful 身份验证创建的夹具文件中。

quentin:
    id: 1
    ...

aaron:
    id: 2
    ...

我删除了这些 ID,一切正常。

于 2009-08-07T14:59:07.170 回答