Ank*_*itG 1 ruby activerecord ruby-on-rails ruby-on-rails-3
我正在尝试编写一个测试用例,我正在寻找一种更简洁的方法来获取与模型相关的嵌套属性
例如
class Category < ActiveRecord::Base
accepts_nested_attributes_for :devices, :books
#other association and code is not written here
end
Run Code Online (Sandbox Code Playgroud)
我预计
$ Category.get_nested_attributes #this is a dummy method
$ ["devices","books"] #this is the return i expect
Run Code Online (Sandbox Code Playgroud)
是否有现有的辅助方法?如果是,请告诉我.:)
谢谢
根据rails源代码(https://github.com/rails/rails/blob/master/activerecord/lib/active_record/nested_attributes.rb#L269),此代码应该有效:
1.9.3p327 :002 > User.nested_attributes_options.keys
=> [:subscriptions]
Run Code Online (Sandbox Code Playgroud)