Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在序列化过程中包含habtm关系_Ruby On Rails_Ruby On Rails 3_Associations - Fatal编程技术网

Ruby on rails 如何在序列化过程中包含habtm关系

Ruby on rails 如何在序列化过程中包含habtm关系,ruby-on-rails,ruby-on-rails-3,associations,Ruby On Rails,Ruby On Rails 3,Associations,在我的rails 3应用程序中,我有一个has_和属于许多关联。我还使用新的respond_with方法为RESTAPI自动生成XML HABTM关联在数据源和参数之间,联接表是数据源和参数 当我使用DataSource.all编写respond\u时:include=>parameter,它工作正常,我得到了预期的响应 <data-sources type="array"> <data-source> <created-at type="datetime">

在我的rails 3应用程序中,我有一个has_和属于许多关联。我还使用新的respond_with方法为RESTAPI自动生成XML

HABTM关联在数据源和参数之间,联接表是数据源和参数

当我使用DataSource.all编写
respond\u时:include=>parameter
,它工作正常,我得到了预期的响应

<data-sources type="array">
<data-source>
<created-at type="datetime">2011-04-05T14:05:22Z</created-at>
<id type="integer">1</id>
<updated-at type="datetime">2011-04-05T14:05:22Z</updated-at>
<url>http://www.yahoo.com/weather</url>
<parameters type="array"/>
</data-source>
</data-sources>

2011-04-05T14:05:22Z
1.
2011-04-05T14:05:22Z
http://www.yahoo.com/weather
响应表示每个数据源的参数将包含在数据源中。但是,这仅在没有实际关联存在时有效,即联接表为空

在我实际创建两个数据库条目之间的关联时,我得到了错误“undefined method`type'for nil:NilClass”,并且日志指向上面的代码行


有人能帮我弄清楚为什么会发生这种情况吗?

你看过这个吗?
你看了这个吗?

您正在rails3中使用habtm?为什么不使用
has\u many:through
?没有其他模型链接数据源和参数。您建议如何使用has_many:through?对不起,我觉得habtm不受欢迎,但事实并非如此。您的关系肯定可以实现为:通过,但是如果您不需要访问连接上的任何数据,那就没有意义了。您在rails3中使用的是habtm吗?为什么不使用
has\u many:through
?没有其他模型链接数据源和参数。您建议如何使用has_many:through?对不起,我觉得habtm不受欢迎,但事实并非如此。您的关系肯定可以实现为:通过,但如果您不需要访问连接上的任何数据,则没有意义。