ruby-on-rails – 从以下各项获取关联列表:accepts_nested_attributes_for

ruby-on-rails – 从以下各项获取关联列表:accepts_nested_attributes_for,第1张

概述我想得到一个模型:accepts_nested_attributes_for的关联列表.例如,我想从这个模型中获得[:children,:other_children]: class ParentResource < ActiveRecord::Base has_many :children has_many :other_children has_many :non_nested_c 我想得到一个模型:accepts_nested_attributes_for的关联列表.例如,我想从这个模型中获得[:children,:other_children]:

class ParentResource < ActiveRecord::Base  has_many :children  has_many :other_children  has_many :non_nested_children  accepts_nested_attributes_for :children,:other_childrenend

现在,我正在使用以下函数执行此 *** 作:

def self.nested_associations  reflect_on_all_associations.map(&:name).select do |association_name|    association_name if method_defined?("#{association_name}_attributes=".to_sym)  endend

然而,我觉得有一种烘焙方式来获得这个阵列.如果是这样,那么正确的方法是什么.

解决方法 我不确定这是’正确的方法’,但你不能这样做:

ParentResource.nested_attributes_options.keys
总结

以上是内存溢出为你收集整理的ruby-on-rails – 从以下各项获取关联列表:accepts_nested_attributes_for全部内容,希望文章能够帮你解决ruby-on-rails – 从以下各项获取关联列表:accepts_nested_attributes_for所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1281940.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存