$50 to anyone - 1 form - multiple models, HMT w/check_boxes

Hi Guys,

Firstly apologies for posting again.

I have been through a load of headache and days deep in google trying to
find an example/solution to my problem.
A lot of good people have been helping out a lot but I still haven't
managed to knock it over yet.

So, I am offering $50USD (via paypal) to anyone who can get this working
for me. Or I can send you something cool from Thailand (where I live)

I have the following models in a has_many :through relationship.
Job, Division, JobDivisions.

Each job can involve any number of divisions.

The 3 things I need to do:
  1. When I create a new Job I want to be able to select the appropriate
divisions using checkboxes.
  2. I guess I will probably need to edit a job later - add/remove
divisions
  3. The other step in 'setting up a job' is I have a script that builds
a bunch of different directories depending on the divisions the job has.
This, hopefully, will get information from the JobDivisions JOIN table -
basically 'how many directories for each division to build'.

Most importantly I need to work out point (1).

Maybe the only problem is that I have no idea how to use the checkbox's
output to create new JobDivisions.

NOTES:
I am using form_for, but am wondering if I should be using form_for_tag
My tables seem to be ok - the JobDivision table has job_id:integer,
division_id:integer & one called shotamount:integer - for point (3)
above.

Please help!

Very Sincerely!, Adam

As for errors I currently get:

Adam --

Is it feasible to use something like active scaffold?
http://activescaffold.com

If so, that's the easiest way I know to solve this. If not, I'd still
be happy to help.

Matt

I was trying to do something similar and found a much better approach
than using checkboxes, which was ugly in code and UI. Check out these
Railscasts, just following these through gave me a good start:

http://railscasts.com/episodes/73
http://railscasts.com/episodes/74
http://railscasts.com/episodes/75

I think i might be getting closer!

But I am getting this error (does it mean it is trying to save the Join
table before it has created a Job? and therefore can't reference a
job_id?) :

THE ERROR:

Adam --

In your controller's create, you have:

   @job = Job.new(params[:job])
   @job.user_id = session[:user_id]

   params[:divisions].each_value do |k|
    @job.job_divisions.build(k)
   end

The problem is that it hasn't created an id for the job yet, so it can't
define the relationship between the job and the division.

You need to save the job prior to adding the divisions.

@job.save!

Hope this helps,
Matt