GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
I have managed to create a drop-down that is filled from the service model. The service model is managed from a MySQL table. I used this code:
f.input :service, :as => :select #<-- :as not really needed, I know...
I would like to have another select box below the service select that is filled with teams from the team model (teams table in MySQL database) based on what the user selected from the service select.
For example if Service 1 was selected from the service select then the team select would be filled with the teams (Team 1, Team 2) that have the foreign key of service_id = 1 in the teams table in the database. If anyone could help with how to insert the correct associations and Formtastic code to achieve this I would greatly appreciate it.
You might consider a custom input TeamSelectInput that subclasses SelectInput (:as => :team_select), then you can hook into various methods there to add-in extra markup on each <option> (like a data attribute or a class for each Service). Closing for now, but happy for you re-open if you need further help with the Formtastic side of this (generating markup that will help you hook up the JS you need.
:as => :team_select