Rails ActiveAdmin. How to set default value?

Seybo Glaux picture Seybo Glaux · May 21, 2016 · Viewed 8.7k times · Source

I have code like this:

ActiveAdmin.register Post do

form do |f|
  f.inputs "Post Details" do
    f.input :title
    f.input :body
    f.input :published_at, :as => DateTime.now
  end
  f.actions
end

I want the field :published_at (which is t.datetime) to be set to the current date and time by default. My example doesn't work. How can I achieve this?

Answer

Seybo Glaux picture Seybo Glaux · May 22, 2016

Yep. Found the answer myself.

ActiveAdmin.register Post do

form do |f|
  f.object.published_at = DateTime.now
  f.inputs "Post Details" do
    f.input :title
    f.input :body
    f.input :published_at
    ...
  end
end