5

我在为我的应用程序运行路由时遇到了一些问题。

1.

我希望能够将活动管理员指向http://admin.lvh.me:3000/ 我尝试使用此代码,但它只显示索引页面。

# config/routes.rb
scope :admin, constraints: { subdomain: "admin" } do
  ActiveAdmin.routes(self)
  devise_for :admin_users, ActiveAdmin::Devise.config.merge(path: "/")
end

# config/initializers/active_admin.rb
config.default_namespace = :admin

唯一有效的网址是http://admin.lvh.me:3000/admin 是否可以避免/admin

2.

我的应用程序中的每个考试都有很多部分。我想使用此代码为每个考试添加一个部件按钮。

# app/admin/exams.rb
ActiveAdmin.register Exam do
  # ...
  index do
    column :actions do |exam|
      link_to "Part", admin_exam_parts_path(exam)
    end

    default_actions
  end
  # ...
end

问题是那admin_exam_parts_path不存在。

# config/routes.rb
scope :admin, constraints: { subdomain: "admin" } do
  resources :exams do
    resources :parts
  end

  ActiveAdmin.routes(self)
  devise_for :admin_users, ActiveAdmin::Devise.config.merge(path: "/")
end

rake routes | grep /admin/exams/:exam_id/parts不返回任何东西。我做错了什么?

我在跑

  • 活跃管理员 0.5.1
  • 导轨 3.2.12
  • 红宝石 1.9.3
4

2 回答 2

0

"admin" is the default namespace for all resources.

you can turn off a resources namespace explicitly in the registration block like this:

ActiveAdmin.register Exam, :namespace => false  do
  ...
end

as far as you has_many: :parts association, can you post the code for your registration block for Parts? There are several ways I might set up this relationship depending on what I was trying to accomplish. So the more context you can give me, the better

于 2013-06-30T16:37:59.913 回答
0

对于你的第一个问题,我的 routes.rb 上有这个

root to: "admin/dashboard#index"

在资源之后和 devise_for 之前,工作得很好!

祝你好运!

于 2013-06-14T08:28:14.593 回答