Summary of what I'd like to accomplish:
I'm performing a side-by-side comparison of two table objects and their data housed in multiple tables. The model associations are as sumarized:
Team (has_many (of all other data tables) Other Data (belongs_to (team)
It's not written this way, just easier to summarize.
I want to have two dropdowns populating the team names from the teams table with ID being the key during form submission for the other table data being retrieved.
When the data is retrieved, I want to render the data through a partial.
Here's what I have as a generic start point:
Routes file
map.virtual_matchups '/virtual_matchups', :controller => 'teams', :action => 'virtual_matchups'
Teams Controller
def virtual_matchups @teamnames = Team.find(:all, :order => "name ASC") @teamsearch = ... ? ...
render :partial => 'datareturned'
respond_to do |format| format.html # index.html.erb format.xml { render :xml => @teams } end end
virtual_matchups.html.erb file
<div class="centerAlign"> <ul class="leftAlign"> <%= collection_select(:team, :id, @teamnames, :id, :name, options ={:prompt => "- Select Team One"}, :class =>"teamselect") %> <%= collection_select(:team, :id, @teamnames, :id, :name, options ={:prompt => "- Select Team Two"}, :class =>"teamselect") %> </ul> </div>
I don't have the form for in, nor do I have the submit button. I need to understand and have the following questions answered:
1. How do I designate each collection_select so that when I perform my submit, the search knows which data to pull for each team?
2. Is my route setup correctly? Or, should I be using something similar to: map.resources :teams, :collection => {:virtual_matchups => :get}
3. My @teamsearch instance variable is currently not setup because I'm not sure what params I will be sending to the model, or how to send it to multiple models the correct way. Because I'm pulling data from approx. 37 different tables for two separate teams, I'd like to do it properly and eagerly load if possible. What should I do?
4. I have not setup my datareturned partial yet because again, I'm unsure of what I need to do first to pull the data so if there's something special I should do here, or should keep in mind when creating it, please let me know?
Any help or advice would be appreciated on this. I've tried spending a few days researching this on my own but I can't seem to find anything that uses a side-by-side comparison example, nor at the same time pulling data from multiple models. As I'm a bit stumped, I could use some assistance getting through this bit.
Thanks.