# Activerecord.save attributes not saved

**URL:** <https://www.ruby-forum.com/t/activerecord-save-attributes-not-saved/50045>\
**Category:** Rails\
**Created:** [December 12, 2005, 3:57pm UTC](https://www.ruby-forum.com/t/activerecord-save-attributes-not-saved/50045 "2005-12-12T15:57:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergi\_Borras](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Sergi\_Borras](https://www.ruby-forum.com/u/Sergi_Borras)\
**Post date:** [December 12, 2005, 3:57pm UTC](https://www.ruby-forum.com/t/activerecord-save-attributes-not-saved/50045/1 "2005-12-12T15:57:03Z")

</div>

Hi there,

I just added two new attributes, created (datetime) and user\_id in a db  
entity called documents. Those two new attributes are not being saved to  
the  
db by the activerecord model ‘document’, they remain null after @  
document.save. I tried restarting the server, but the problem remains  
the  
same

Model :

class Document \< ActiveRecord::Base  
has\_many :tag\_actions  
has\_one :user  
end

Controller create method

def create  
@document = Document.new  
@document.title = params[:document][‘title’]  
@document.body = params[:document][‘body’]  
@document.created = DateTime.now.strftime(“Y-%m-%d %H:%M:%S”)  
@document.user = User.find(session[:user\_id])  
if @document.save  
flash[:notice] = ‘Document was successfully created.’  
else  
flash[:notice] = ‘Could not create document.’  
end  
redirect\_to :action =\> ‘list’  
end

---

<div class="post-metadata">

**Author:** ![Sergi\_Borras](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Sergi\_Borras](https://www.ruby-forum.com/u/Sergi_Borras)\
**Post date:** [December 12, 2005, 4:27pm UTC](https://www.ruby-forum.com/t/activerecord-save-attributes-not-saved/50045/2 "2005-12-12T16:27:15Z")

</div>

you should have:

class Document \< ActiveRecord::Base  
belongs\_to :user  
has\_many :tag\_actions  
…  
end

class User \< ActiveRecord::Base  
has\_many :documents  
…  
end

also, if you use the magic db field name ‘created\_on’ of type datetime  
(i’m  
making the assumption you are using mysql), the datetime value for this  
field will automatically be generated by AR upon creating the record.

def create  
@document = Document.new(@params[:document])  
@document.user\_id = @session[:user\_id]  
if @document.save  
flash[:notice] = “Document was successfully created”  
redirect\_to :action =\> :list  
else  
flash.[:notice] = “Could not create document”  
render :action =\> :new  
end  
end
