Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin and custom method

This is my custom page in Active Admin

ActiveAdmin.register_page "Settings" do

  action_item do
     link_to('Import projects', 'settings/importprojects')
  end

  content do
    para "Text"
  end

  controller do
    def importprojects
      system "rake dataspider:import_projects_ninja"
      para "OK"
    end
  end

end

What I'm trying to do is, when I click on the button 'import projects', I want to preform a rake task with is in the controller. But I can't access the method.

What could be the problem or what I'm a doing wrong?

Thanks

like image 931
Kevin Gorjan Avatar asked Apr 17 '12 14:04

Kevin Gorjan


1 Answers

Okay, found it and here is the solution:

  sidebar :actions do
    button_to "Update projects", "/admin/projects/updateprojects", :method => :post, :confirm => "Are you sure?"
  end

  collection_action :updateprojects, :method => :post do
    system "rake dataspider:import_projects_ninja"
    redirect_to admin_projects_path, :notice => "Syncing..."  
  end

I created an button and it runs the method 'updateprojects'

like image 119
Kevin Gorjan Avatar answered Sep 23 '22 11:09

Kevin Gorjan