Use of push_with_attributes


I have a model class called Page and a corresponding pages table in the

Is there a way to do without actually creating a corresponding
record in the table? I want to set some values in it and then pass it to
the add_content_component() method in the class below which calls
push_with_attributes() which will actually create the record in the db?

class Page < ActiveRecord::Base
has_and_belongs_to_many :contentcomponents

def add_content_component(content_component)
pos = Integer(contentcomponents.size) + 1
contentcomponents.push_with_attributes(content_component, :pos =>


Or am I all messed up and I should be taking a different approach?



If I understand you correctly all you need to do is:

page =

Then pass the “page” variable wherever you need it to go. It won’t be
created in the database until you do

Also, I believe push_with_attributes has been deprecated in favor of
has_many :through. Check it out, it may make things ismpler for you.