Activeadmin 自定义控制器新动作
Activeadmin customize controller new action
谁能解释一下如何自定义 Activeadmin 控制器的新操作?我有这样的 类:Room
、Option
和 RoomOption
。它们在 has_many through
关联中,我希望能够基于数据库中存在的 Options
为每个新的 Room
构建 RoomOptions
。
我有这样的代码:
controller do
def new
super
Option.find_each { |option| resource.room_options.build(option: option)}
end
end
但它不起作用,因为没有创建选项。
我会使用:
def new
build_resource
Option.find_each { |option| resource.room_options.build(option: option) }
new!
end
房型必须accept_nested_attributes可供选择。
谁能解释一下如何自定义 Activeadmin 控制器的新操作?我有这样的 类:Room
、Option
和 RoomOption
。它们在 has_many through
关联中,我希望能够基于数据库中存在的 Options
为每个新的 Room
构建 RoomOptions
。
我有这样的代码:
controller do
def new
super
Option.find_each { |option| resource.room_options.build(option: option)}
end
end
但它不起作用,因为没有创建选项。
我会使用:
def new
build_resource
Option.find_each { |option| resource.room_options.build(option: option) }
new!
end
房型必须accept_nested_attributes可供选择。