如何修复似乎不起作用的ActiveAdmin“编辑”操作路线

时间:2019-10-27 20:47:10

标签: ruby-on-rails ruby activeadmin

我刚刚创建了活动的管理仪表板,并且一切似乎正常,但是创建新的管理用户时,我收到了URLGeneration错误,尽管该用户是在返回仪表板时创建的。当我尝试“查看”我刚刚创建的用户或包括默认管理员用户在内的任何用户时,也会发生相同的错误。单击“ admin”用户的“ Id”后,情况也是如此。

(错误)

     ActionController::UrlGenerationError in Admin::AdminUsers#show

showing .../bundler/gems/activeadmin-b9f189ff671a/app/views/active_admin/resource/show.html.arb where line #2 raised:

 No route matches {:action=>"edit", :controller=>"admin/admin_users", :id=>#<User id: nil, email: "", created_at: nil, updated_at: nil, name: nil, provider: nil, uid: nil, image: nil>}, possible unmatched constraints: [:id]

(config / routes.rb)

Rails.application.routes.draw do
 devise_for :admin_users, ActiveAdmin::Devise.config
 ActiveAdmin.routes(self)

(models / admin_user.rb)

class AdminUser < ApplicationRecord
 devise :database_authenticatable, 
     :recoverable, :rememberable, :validatable
end

管理文件:

(admin / admin_users.rb)

ActiveAdmin.register AdminUser do
  permit_params :email, :password, :password_confirmation

  index do
    selectable_column
    id_column
    column :email
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end

  filter :email
  filter :current_sign_in_at
  filter :sign_in_count
  filter :created_at

  form do |f|
    f.inputs do
      f.input :email
      f.input :password
      f.input :password_confirmation
    end
    f.actions
  end

end

(admin / dashboard.rb)

ActiveAdmin.register_page "Dashboard" do

  menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }

  content title: proc{ I18n.t("active_admin.dashboard") } do
    div class: "blank_slate_container", id: "dashboard_default_message" do
      span class: "blank_slate" do
        span I18n.t("active_admin.dashboard_welcome.welcome")
        small I18n.t("active_admin.dashboard_welcome.call_to_action")
      end
    end

  end # content
end

1 个答案:

答案 0 :(得分:0)

No route matches {
 :action=>"edit", 
 :controller=>"admin/admin_users", 
 :id=>#<User id: nil, email: "", created_at: nil, updated_at: nil, name: nil, provider: nil, uid: nil, image: nil>
}, possible unmatched constraints: [:id]

我在上面的读物是edit路由期望一个ID,但得到一个错误的值。与此结合

ActionController::UrlGenerationError in Admin::AdminUsers#show

加上您所做的描述,使我相信edit视图内生成show链接的方式存在问题。

您可以更新您的问题以包括ActiveAdmin“显示”视图吗?包括您的ActiveAdmin资源文件(应位于app/admin中)也将很有帮助。