ActiveAdmine register_page和控制器

时间:2016-01-19 20:51:24

标签: ruby-on-rails activeadmin

这样定义的行动的链接是什么:

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和控制器如何合作感到错误?

2 个答案:

答案 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确认操作可用。

参考:http://activeadmin.info/docs/10-custom-pages.html

答案 1 :(得分:1)

似乎ActiveAdmin在下划线方面存在一些问题,因为您可以看到here

尝试重命名您的网页

ActiveAdmin.register_page "Such Page" do
  ...
end

你将在你的路线中得到这个

admin_such_page GET         /admin/such_page(.:format)       admin/such_page#index