rails-administrator+design创建新用户去设计控制器



我正在使用rails administrator开发rails应用程序。我有一个名为admin_users的资源的管理界面,由design控制。现在,用户实际上只在rails控制台中生成,并且添加了design以允许用户具有omnauth功能。在这个面板上,我想要一个选项,为我想邀请到应用程序中的其他用户创建admin_user,因为这比在生产中从rails控制台执行更容易。

我有一个控制器Admin::AdminUsersController来处理这个功能,以匹配仪表板。现在,它列出了系统中当前的adminuser,这些adminuser是从rails控制台创建的,运行良好。

现在,我添加了从rails administrator界面创建管理员用户的选项。然而,当在admin/admin_users/new上填写表单时,design似乎拦截了请求,并且似乎试图将我注销。查看我的rails服务器,以下是日志

app_1  | Started POST "/admin/admin_users" for 192.168.96.1 at 2020-02-25 02:38:41 +0000
app_1  | Cannot render console from 192.168.96.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
app_1  | Processing by Devise::RegistrationsController#create as HTML
app_1  |   Parameters: {"authenticity_token"=>"LPbT7OCx8upC5ehWIZ1JV/o/UKttciyoThOgi06B4AUw8ve3x/stbjUT7Trvb9u0YMEoyEBobbbni0g7LNWvBg==", "admin_user"=>{"email"=>"test@somemail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "reset_password_token"=>"[FILTERED]", "reset_password_sent_at"=>"[FILTERED]", "remember_created_at"=>""}, "commit"=>"Create Admin user"}
app_1  |   AdminUser Load (0.6ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", "2d795b9d-2b6f-4745-a58d-775076100c60"], ["LIMIT", 1]]
app_1  | Redirected to http://localhost:3000/
app_1  | Filter chain halted as :require_no_authentication rendered or redirected
app_1  | Completed 302 Found in 6ms (ActiveRecord: 0.6ms | Allocations: 2088)
app_1  | 
app_1  | 
app_1  | Started GET "/" for 192.168.96.1 at 2020-02-25 02:38:41 +0000
app_1  | Cannot render console from 192.168.96.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
app_1  | Processing by Rails::WelcomeController#index as HTML
app_1  |   Rendering /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/templates/rails/welcome/index.html.erb
app_1  |   Rendered /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/templates/rails/welcome/index.html.erb (Duration: 3.6ms | Allocations: 201)
app_1  | Completed 200 OK in 6ms (Views: 5.4ms | ActiveRecord: 0.0ms | Allocations: 1004)
app_1  | 

我无法让控制器执行我的Admin::AdminUsersController#create操作。从日志来看,它似乎在/admin/admin_users到达了我的post路由,在Devise::RegistrationsController#create被design拦截,从Filter chain halted as :require_no_authentication被阻止,然后重定向到我的根路由,这与我注销时类似。

我甚至添加了一个视图来覆盖管理员在app/views/admin/admin_users/new.html.erb的默认视图,以触发表单转到我要查找的控制器操作,就像一样

<section class="main-content__body">
<%= form_for([namespace, page.resource], :url => url_for(:controller => 'admin/admin_users', :action => 'create'), html: { class: "form" }) do |f| %>
<% if page.resource.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(page.resource.errors.count, "error") %>
prohibited this <%= page.resource_name %> from being saved:
</h2>
<ul>
<% page.resource.errors.full_messages.each do |message| %>
<li class="flash-error"><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<% page.attributes.each do |attribute| -%>
<div class="field-unit field-unit--<%= attribute.html_class %>">
<%= render_field attribute, f: f %>
</div>
<% end -%>
<div class="form-actions">
<%= f.submit %>
</div>
<% end %>
</section>

我还尝试在我的路线中添加devise_scope :admin_user,如

devise_scope :admin_user do
post "/admin/admin_users", to: 'admin/admin_users#create'
end

它什么也没做。

我想要的功能是,当我在admin_users面板上时,使用Admin::AdminUsersController#create操作而不是Devise::RegistrationsController#create操作创建admin_user。

有人知道我需要添加什么才能启用吗?

您尝试过命名空间吗?

namespace :admin do 
devise_for :users
# if the above doesn't work 
# devise_for :admin_users
end

此外,您可以尝试覆盖Administrate基本控制器,如下所述:https://stackoverflow.com/a/59824297/1737811具有必要的字段。

相关内容

  • 没有找到相关文章

最新更新