I have a table called users in a PostgreSQL database. It has name, country and created_date columns. If I insert a new user record with name and country values, created_date got inserted automatically. When I tried to do the same using Ruby code, created_date field is null. My definition for create is given below. How can I insert created_date automatically.
def create
@new_user = User.new(params[:user])
@new_user.save
end
Note: params[:user] contains name and country values
Rails will automatically manage only created_on and created_at columns as you can see from ActiveRecord::Timestamp source. Difference between _at and _on is that _at contains full datetime, while _on contains only date. If you use migrations you can create ‘created_at’ and ‘updated_at’ with t.timestamps.