Drakmail
Drakmail

Reputation: 692

ActiveAdmin collection action path

How do I set the url for a "semantic form" tag in an activeAdmin custom page partial for collection_action in my activeAdmin controller?

I have:

item.rb

ActiveAdmin.register Item, :as => "MyItems" do
  menu :parent => "My", :label => "My Items"

  collection_action :add_me, :method => :post do
    redirect_to "/" # just for testing
  end
end

custom page ActiveAdmin controller

ActiveAdmin.register_page "MyItemsCustomPage" do
  content do
    @items = Item.all
    render "item", { :items => @items }
  end
end

_item.html.erb (for custom page)

<%= semantic_form_for :item_add_me, :url => add_me_admin_items_path do |f| %>
    <%= f.buttons :commit %>
<% end %>

And after going to the custom page I have the error:

undefined local variable or method `add_me_admin_items_path' for #<#<Class:0x00000006c3ff40>:0x00000005f8bd80>

btw, semantic form for admin_items_path works well for item add action.

PS. If I change the url to /admin/items/add_me and set the :method to :post, I get the routing error: No route matches [POST] "/admin/items/add_me"

Upvotes: 0

Views: 5200

Answers (2)

Josh Kovach
Josh Kovach

Reputation: 7749

The problem here is that ActiveAdmin.register Item, as: "MyItems" actually renames all your routes to be my_items instead of my_item in all the method names. So, in your form, instead of using add_me_admin_items_path, you could have used add_me_admin_my_items_path.

Upvotes: 0

Drakmail
Drakmail

Reputation: 692

Found the problem.

After removing :as => "MyItems" in item.rb:

ActiveAdmin.register Item do

All works ok.

Upvotes: 1

Related Questions