这样定义的行动的链接是什么:
ActiveAdmin.register_page "such_page" do
content title: 'A page' do
columns do
column do
render partial: 'index'
end
end
end # content
action_item do
link_to('Perform', 'such_page/much_action')
end
controller do
def much_action
puts 'Wow, actually doing!'
redirect_to 'http://stackoverflow.com'
end
end
我认为链接会像action_item
中提到的那样,但会导致404错误页面。我是否忘记添加一些路线,或者我对ActiveAdmin register_page
和控制器如何合作感到错误?
答案 0 :(得分:2)
在Active Admin页面中,您必须定义自定义操作,如下所示:
ActiveAdmin.register_page "such_page" do
#...
action_item do
# please refer to rake routes for the exact route name
link_to('Perform', admin_much_action_path)
end
page_action :much_action do
puts 'Wow, actually doing!'
redirect_to 'http://stackoverflow.com'
end
#...
end
使用page_action
将自动配置路由。您可以致电rake routes
确认操作可用。
答案 1 :(得分:1)
似乎ActiveAdmin在下划线方面存在一些问题,因为您可以看到here。
尝试重命名您的网页
ActiveAdmin.register_page "Such Page" do
...
end
你将在你的路线中得到这个
admin_such_page GET /admin/such_page(.:format) admin/such_page#index