0

I have one model (Group) associated with my GroupController, but it has many instances of another model (People) in it. I want to be able to create new instances of People from my GroupController and add it to an array. What is the best way to go about doing this? The following is an excerpt from the GroupController:

    class Group < Volt::ModelController
      field :people_in_group        

      def add_people(name)
        people_in_group = []
        person = People.new(name)
        people_in_group << person
      end

    end

The function breaks when I try to create a new person. Any advice?

user3579220
  • 187
  • 1
  • 2
  • 9

2 Answers2

1

Is this supposed to be a model? If so it should inherit from Volt::Model not Volt::ModelController

Thanks!

Ryan
  • 956
  • 7
  • 8
0

Try something like this:

class Person < Volt::Model
  field :name, String
  def initialize(a_name)
    @name = a_name
  end
end

class Group < Volt::Model
  has_many :people

  def add_people(name)
    people << Person.new(name)
  end

end
Jason Southwell
  • 351
  • 2
  • 9