Rest is giving me no rest (more weirdness)

I was here last week working out a correct link_to path for a nested resource. Through the help I received things were resolved with that issue. Now, I’m having a related issue.

For clarification my routes.rb (the rest parts) is here:

map.resources :candidates do |candidate| candidate.resources :canbackgrounds

Now originally I had the models set up as such:

class Candidate < ActiveRecord::Base has_many :canbackgrounds

class Canbackground < ActiveRecord::Base belongs_to :candidate

However , part of fixing my problem last week was changing the Candidate model to: class Candidate < ActiveRecord::Base has_one :canbackground

All was good until I went to candidates/id/canbackgrounds/new After inputing the data, my controller code (canbackgrounds_controller.rb) threw a no-method error on the create action: def create @canbackground = Canbackground.new(params[:canbackground]) @candidate_id = params[:candidate_id]

if (@candidate.canbackgrounds << @canbackground) <-----This was the line, with no method ‘canbackgrounds’

  redirect_to candidate_url(@candidate)

else render :action => :new end end

I thought maybe it needed to be singular but then << threw a no method error. I went back to the model and changed the Candidate to has_many :canbackgrounds and that fixed the problem.

However if I leave it like this then I’m back to the same problem as last week. So , one I’m open to hearing if anyone has any ideas about what’s going on , and could the create problem be related to the fact that a canbackground record already existed when I was attempting to insert another one ?

TIA Stuart