8
난과 같이 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