Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails ActiveAdmin. How to set default value?

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?

like image 809
Seybo Glaux Avatar asked May 21 '16 18:05

Seybo Glaux


Video Answer


2 Answers

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
like image 119
Seybo Glaux Avatar answered Oct 18 '22 04:10

Seybo Glaux


You can try with something like this:

<%= f.input :published_at, input_html: {value: "#{Time.now}"} %>
like image 26
Flamine Avatar answered Oct 18 '22 04:10

Flamine