Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active admin : form on dashboard not related to any models

I have a rails 3 application which uses the ActiveAdmin gem.

Is there a way to make a form in the dashboard page. A form that is not related to any models ? In my case, a form to select time period to display some stats ?

I have tried :

form do |f|
  f.inputs "test" do
    f.input :time, label: "Duration", as: :select, collection: [['24h', 24], ['1 week', '1w'], ['1 month', '1m']]
  end
  f.actions
end

But i'm getting an "undefined methods errors" for f.inputs. Does someone have an idea ?

like image 688
Jérémy Pouyet Avatar asked Nov 27 '25 16:11

Jérémy Pouyet


1 Answers

You probably need to create a form partial like this:

-# admin/whatever/_form.html.haml
= semantic_form_for 'whatever', :url => admin_whatevers_path do |f|
  = f.inputs :name => 'tests' do %>
    = f.input :time, collection: [['24h', 24], ['1 week', '1w'], ['1 month', '1m']]

and tell activeadmin to use the partial like this:

#admin/whatever.rb
form :partial => 'form'
like image 169
David Avatar answered Nov 30 '25 10:11

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!