I was SO close to successfully updating my HABTM relationship!
Here’s my schema:
create_table “people”, :force => true do |t|
t.column “family_name”, :string
t.column “given_name”, :string
t.column “email”, :string
t.column “keitai_email”, :string
t.column “photo”, :binary
t.column “telephone_extension”, :integer
t.column “hashed_password”, :string
end
create_table “people_projects”, :force => true do |t|
t.column “person_id”, :integer
t.column “project_id”, :integer
end
create_table “projects”, :force => true do |t|
t.column “project_number”, :string
t.column “client_company”, :string
t.column “client_contact”, :string
t.column “contact_email”, :string
t.column “contact_phone”, :string
t.column “open_date”, :date
t.column “close_date”, :date
t.column “project_description”, :text
end
And my controller def:
def update
@project = Project.find(params[:id])
@project.people = Person.find(params[:addpersonid]) if
params[:addpersonid]
if @project.update_attributes(params[:project])
flash[:notice] = ‘Project was successfully updated.’
redirect_to :action => ‘show’, :id => @project
else
render :action => ‘edit’
end
end
And the code in the view that calls that def:
TEAM
<% team = Project.find(@id).people.find(:all) %> <% for p in @people -%>According to my best guess, everything should work now. But I suddenly
got this “undefined method `each’” error. I’ve done a search on my
controller and the word “each” doesn’t even exist in it. Does anybody
know what’s going on here?
Thanks
sean