Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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 Rails Braintree gem订阅类冲突_Ruby On Rails_Subscription_Braintree - Fatal编程技术网

Ruby on rails Rails Braintree gem订阅类冲突

Ruby on rails Rails Braintree gem订阅类冲突,ruby-on-rails,subscription,braintree,Ruby On Rails,Subscription,Braintree,在我的Rails应用程序中,我使用Braintree gem创建订阅。在没有意识到的情况下,我还创建了一个订阅模型和控制器来管理我想在本地存储的订阅信息。在我的模型中,订阅可以属于用户。然而,你能做的一些正常的事情不起作用,比如 当前用户.subscriptions.build() 但由于某种原因,当有人帮助我时,他们能够使用 current_user.create_subscription 此创建订阅方法在何处定义?它是否以某种方式凌驾于Rails惯例之上 我注意到Braintree gem

在我的Rails应用程序中,我使用Braintree gem创建订阅。在没有意识到的情况下,我还创建了一个订阅模型和控制器来管理我想在本地存储的订阅信息。在我的模型中,订阅可以属于用户。然而,你能做的一些正常的事情不起作用,比如 当前用户.subscriptions.build()

但由于某种原因,当有人帮助我时,他们能够使用

current_user.create_subscription
此创建订阅方法在何处定义?它是否以某种方式凌驾于Rails惯例之上


我注意到Braintree gem中有一个subscription.rb文件。与Braintree和我的订阅模型定义的类是否存在冲突?我知道我可能可以重命名我的订阅模型,但我很好奇冲突是什么

您的问题是订阅关系是has_one或belown_to,而不是has_many。在这种情况下,用户将没有订阅方法,因为附加的订阅是单数的。查看API文档,了解如何在AR中处理这些关系

从上的手册中有一个:

The following methods for retrieval and query of a single associated object will be added: association(force_reload = false) Returns the associated object. nil is returned if none is found. association=(associate) Assigns the associate object, extracts the primary key, sets it as the foreign key, and saves the associate object. build_association(attributes = {}) Returns a new object of the associated type that has been instantiated with attributes and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if an association already exists. It will NOT work if the association is nil. create_association(attributes = {}) Returns a new object of the associated type that has been instantiated with attributes, linked to this object through a foreign key, and that has already been saved (if it passed the validation). 将添加以下检索和查询单个关联对象的方法: 关联(强制重新加载=错误) 返回关联的对象。如果没有找到,则返回nil。 关联=(关联) 指定关联对象,提取主键,将其设置为外键,并保存关联对象。 建立关联(属性={}) 返回关联类型的新对象,该对象已使用属性实例化并通过外键链接到此对象,但尚未保存。注意:这仅在关联已经存在时有效。如果协会为零,它将不起作用。 创建_关联(属性={}) 返回关联类型的新对象,该对象已使用属性实例化,通过外键链接到此对象,并且已保存(如果已通过验证)。
Braintree确实有一个Subscription类,但它的名称空间是Braintree:Subscription,因此它不是问题。

您的问题是订阅关系是has\u one或belimited\u to,而不是has\u many。在这种情况下,用户将没有订阅方法,因为附加的订阅是单数的。查看API文档,了解如何在AR中处理这些关系

从上的手册中有一个:

The following methods for retrieval and query of a single associated object will be added: association(force_reload = false) Returns the associated object. nil is returned if none is found. association=(associate) Assigns the associate object, extracts the primary key, sets it as the foreign key, and saves the associate object. build_association(attributes = {}) Returns a new object of the associated type that has been instantiated with attributes and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if an association already exists. It will NOT work if the association is nil. create_association(attributes = {}) Returns a new object of the associated type that has been instantiated with attributes, linked to this object through a foreign key, and that has already been saved (if it passed the validation). 将添加以下检索和查询单个关联对象的方法: 关联(强制重新加载=错误) 返回关联的对象。如果没有找到,则返回nil。 关联=(关联) 指定关联对象,提取主键,将其设置为外键,并保存关联对象。 建立关联(属性={}) 返回关联类型的新对象,该对象已使用属性实例化并通过外键链接到此对象,但尚未保存。注意:这仅在关联已经存在时有效。如果协会为零,它将不起作用。 创建_关联(属性={}) 返回关联类型的新对象,该对象已使用属性实例化,通过外键链接到此对象,并且已保存(如果已通过验证)。
Braintree确实有一个Subscription类,但这是Braintree:Subscription的名称空间,所以这不是问题所在。

啊,我明白了。我不知道这和你的一个不一样。非常感谢。啊,我明白了。我不知道这和你的一个不一样。非常感谢。