Rest is giving me no rest (more weirdness)

I was here last week working out a correct link_to path for a nested
Through the help I received things were resolved with that issue. Now,
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
threw a no-method error on the create action:
def create
@canbackground =[:canbackground])
@candidate_id = params[:candidate_id]

if (@candidate.canbackgrounds << @canbackground) <-----This was the
with no method ‘canbackgrounds’
redirect_to candidate_url(@candidate)
render :action => :new

I thought maybe it needed to be singular but then << threw a no method
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
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 ?


Without background of your problem, I wonder if that line should be:

if (@candidate.canbackground << @canbackground)

instead of “@candidate.canbackgrounds” (notice the ending ‘s’)?