Hello all,
I want to upate a entry in a one to many relation, but is doesn''t work.
I can add or delete a specific entry, but I can''t update it.
Can anyone help me?
Here is the code:
class Person < ActiveRecord::Base
has_many :materials
end
class Material < ActiveRecord::Base
belongs_to: person
end
class PersonController < ApplicationController
def update
person = Person.find(@params["id"])
person.name = @params["name"]
first_material = person.materials.find(@params["material_id"])
first_material.size = @params["material_size"]
person.update
end
def add
person = Person.new
person.name = @params["name"]
material = person.materials.find(@params["material_id"])
person.materials.push(material)
person.update
end
def delete_material
person = Person.find(@params["id"])
person.name = @params["name"]
material = person.materials.find(@params["material_id"])
person.materials.delete(material)
person.update
end
end
Thanks,
H
--
Posted via http://www.ruby-forum.com/.