Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin form within a custom page

Consider the following ActiveAdmin page:

ActiveAdmin.register_page "Import" do
    content do
        form :action => some_path, :method => :post do |f|
            f.input :name => :table, :collection => { "Display" => "id" }
        end
    end
end

Using this code anywhere within an ActiveAdmin resource works as you would expect, using FormBuilder to create a Formtastic form. When using AA's register_page method, however, and placing a form in the content section, it doesn't seem to work as hoped. Am I missing something or could this be something that's been overlooked? I might create the form in a partial rather than use AA's DSL, but it would be nicer to keep it within the AA resource.

Anyone got a clue why it won't play nice?

like image 309
John Servinis Avatar asked Nov 13 '22 03:11

John Servinis


1 Answers

Actually I noticed that too in the past. My problem was that it seemed Cancan wouldn't work properly anymore when I would go to one of my own custom page...disregarding the admin abilities I had set.

If you look at your logs though, you'll notice that Custom pages render the following:

app/views/active_admin/page/index.html.arb

whereas a "normal" resource page renders the following

app/views/active_admin/resource/index.html.arb

So I think any helpers/methods tied to ActiveAdmin and ActiveRecord models won't work in custom page. Seems like they only work if it renders templates under /resource/*

Just like you said..I went around that problem by creating my own partials !

like image 114
rorofromfrance Avatar answered Nov 14 '22 21:11

rorofromfrance