Reputation: 31548
This is my 2nd day playing with Ruby on Rails, so please be gentle :)
I have a very (hopefully) simple question: I want to set a publish date on my model, when it is indeed being created. I am using Mongoid, and it looks like this:
class Page
include Mongoid::Document
field :content, type: String
field :title, type: String
field :published_on, type: DateTime
end
Here is the question: should I set the published_on
field from the create
action, just before the call to @page.save
? Or is there a better, more idiomatic way?
If I do it like that, meaning, calling @page.published_on = Date.now
from within the controller's action, I get a warning:
Cannot find 'published_on=' for type 'Page'
Upvotes: 2
Views: 351
Reputation: 3499
If you put
class Page
include Mongoid::Document
include Mongoid::Timestamps
you get the rails automagic fields created_at
and updated_at
Upvotes: 3