8
我想通过Activeadmin的formtastic进行动态选择选项,如下所示:Activeadmin formtastic动态选择
form do |f|
f.inputs "Exam Registration Details" do
f.input :user_id, :as => :select, :collection => User.where(:admin => 'false')
#selects user from list. WORKING
f.input :student_id, :as => :select, :collection => Student.joins(lessons: :user)
#collection of students will change to students who have lessons with chosen user. NOT WORKING, returns all students who have lessons.
f.input :lesson_id, :as => :select, :collection => Lesson.joins(:student, :user)
#collection of lessons will change to reflect lessons connected by chosen user and student. NOT WORKING, returns all lessons.
end
f.buttons
end
我的业余代码显然是不工作,我想要它。我应该做什么改变?
我有4种型号如下:
class Student < ActiveRecord::Base
has_many :lessons
has_many :users, through: :lessons
has_many :exam_registrations, through: :lessons
class Lesson < ActiveRecord::Base
belongs_to :user
belongs_to :student
belongs_to :exam_registration
class User < ActiveRecord::Base
has_many :lessons
has_many :students, through: :lessons
has_many :exam_registrations, through: :lessons
class ExamRegistration < ActiveRecord::Base
has_many :lessons
has_many :users, through: :lessons
has_many :students, through: :lessons
感谢您的信息,这个小改动后为我工作。 'config.register_javascript'exam_registrations'' – blotto
很高兴能帮到你! –
@ Ryan.lay:你可以看看http://stackoverflow.com/questions/28187354/active-admin-populate-one-of-the-second-drop-down-after-first – inquisitive