Vorrei fare un'opzione di selezione dinamica tramite Formtastic Activeadmin s' in questo modo:Activeadmin dinamica Formtastic selezionare
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
Il mio codice amatoriale non è, ovviamente, lavorando come ho inteso a. Quali cambiamenti dovrei apportare?
Ho 4 modelli, come di seguito:
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
grazie per le informazioni, questo ha funzionato per me dopo questo piccolo cambiamento. 'config.register_javascript 'exam_registrations'' – blotto
Contento di poterti aiutare! –
@ Ryan.lay: puoi dare un'occhiata a http://stackoverflow.com/questions/28187354/active-admin-populate-one-of-the-second-drop-down-after-first – inquisitive