一个取决于ActiveAdmin形式的其他输入字段的输入
假设我有一个模型:
class User
has_many :books
end
class Book
belongs_to :user
end
现在在Active Admin中,我需要选择任何用户时。该表格将仅显示由该用户创建的书籍。
forms do |f|
f.inputs do
f.input :user, as: :select, collection: User.all
f.input :books, as: :select, collection: Book.all
end
f.actions
end
什么是替换 book.all
的查询?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对Rails 6.0.4
模型
主动admin表单上的依赖性“选择”的这项工作
您必须执行以下操作:
创建一个控制器,以返回子行业。
在
doutes.rb
文件中添加路由。使用您的Web浏览器控制您的选择您的选择,并使用CSS选择器为Select创建jQuery对象,例如:
在文件
/app/app/asps/javascripts/active_admin中添加此代码块。 JS
,负责调用生成的控制器,并添加其返回的选项。参考文献:
无法在我的依赖选择下拉admin上找到错误(Rails 3.2,Active Admin 1.0)
This work for me on dependend "select" on Rails 6.0.4
Models
Active admin form
You must do the following:
Create a controller, that returns the subsectors.
Add the route in the
routes.rb
file.Inspect with your web browser console your selects, and use a CSS selector to create a jQuery object for the sector select, something like:
Add this block of code in the file
/app/assets/javascripts/active_admin.js
, which is responsible for making the call to the generated controller, and adding the options that it returns.References:
Can't find the error in my dependent select drop down on Active Admin( Rails 3.2, Active Admin 1.0)
Populate Select box options on click with Javascript/Jquery with Json data
AS sampat 在评论中提到您可以使用activeadmin 嵌套选择插件。
安装
activeadmin_addons
GEM后,您可以使用:As Sampat mentioned in the comment you can use ActiveAdmin nested select addon.
After installing
activeadmin_addons
gem, you can use: