Trying to figure out how to do an insert into multiple tables from one form.
Models:
class Canbackground < ActiveRecord::Base
  belongs_to :candidate
  has_many :canindustries
end
class Canindustry < ActiveRecord::Base
belongs_to :canbackground
end
------------------------------------------------------------------------
The form looks like this:
<% form_for :canbackground, :url => canbackground_url, :candidate_id =>
@candidate_id do |form| %>  #restful with nested routes
# canbackground is nested route of candidate
.....................................
<td><%= collection_select(:canbackground, :edureq_id, @edureqs, :id,
:name,
{ :prompt => true })%></td> # gets inserted into canbackground
model/table
.................................
<%= collection_select(:canindustry, :category_id,  @categories, :id,
:name,{},"multiple"=>''multiple'',"size"=>5)
%></td>  # should get inserted
into canindustries table
I''m sure the controller is where I need to do something , just not sure
-
def new
@canbackground = Canbackground.new
    @candidate_id = params[:candidate_id]
  end
def create
@canbackground = Canbackground.new(params[:canbackground])
       if (@candidate.canbackgrounds << @canbackground)
         redirect_to candidate_url(@candidate)
       else
         render :action => :new
    end
  end
The candidate_id will need to be inserted into the canindustry model. Not
sure if I need the canbackground_id in the canindustry model.
TIA
Stuart
-- 
http://en.wikipedia.org/wiki/Dark_ambient
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---