背景:应用程序的“添加用户”部分可以在运行两个不同操作系统的两个单独的开发计算机上完美运行:开发机1是运行Catalina(10.15)的Mac,开发机2正在运行Ubuntu衍生软件(Pop!_OS 19.10)。推送到Digital Ocean Dokku服务器后,“添加用户”功能将失败且没有错误;点击提交按钮没有任何作用。“编辑用户”在开发人员和开发人员中都可以使用。
该代码是通过git管理的,没有复杂的部分。因此,相同的代码位于三台计算机上。
我依靠Devise进行用户设置;但是,请跳过注册以限制公众创建帐户。相反,我依靠具有角色的cancancan创建用户。这一切都可以在开发中使用,但是我看不到生产中的适当错误,它只是执行了render:action =>:new而没有任何显式错误。我将Dokku,Rails 6.03与Ruby版本2.7.1结合使用
开发日志
Started POST "/user_managements" for ::1 at 2021-01-23 13:30:48 -0500
Processing by UsersController#create as JS
Parameters: {"authenticity_token"=>"zr4lstDZAfXC3dTf1UADmoa6jbZl5HNQZCuDDdnWBuqa32LtAnadmjYHN+PnVUfs6RFVwcJ03KtpaE/l5osdiQ==", "user"=>{"email"=>"[email protected]", "first_name"=>"Alice", "last_name"=>"Wonderland", "phone_number"=>"", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "superadmin_role"=>"0", "supervisor_role"=>"0", "user_role"=>"1"}, "commit"=>"Submit"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
(0.4ms) SELECT COUNT(*) FROM "stores"
↳ app/controllers/application_controller.rb:33:in `set_search'
(0.2ms) BEGIN
↳ app/controllers/users_controller.rb:22:in `create'
User Exists? (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "[email protected]"], ["LIMIT", 1]]
↳ app/controllers/users_controller.rb:22:in `create'
User Create (0.4ms) ***INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at", "first_name", "last_name", "phone_number") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["email", "[email protected]"], ["encrypted_password", "$2a$11$VNfiMFc2CrDrdtsa31wXkOyhz4D4TkPVTiyDfceO62UwfZdS9fAhS"], ["created_at", "2021-01-23 18:30:49.138574"], ["updated_at", "2021-01-23 18:30:49.138574"], ["first_name", "Alice"], ["last_name", "Wonderland"], ["phone_number", ""]]***
↳ app/controllers/users_controller.rb:22:in `create'
(9.6ms) COMMIT
↳ app/controllers/users_controller.rb:22:in `create'
Redirected to http://localhost:3000/user_managements
Completed 200 OK in 257ms (ActiveRecord: 11.3ms | Allocations: 8092)
生产日志(请注意缺少“ INSERT”语句。)
Started POST "/user_managements" for 173.170.223.213 at 2021-01-23 17:35:02 +0000
2021-01-23T17:35:02.954032036Z app[web.1]: I, [2021-01-23T17:35:02.953856 #10] INFO -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] Processing by UsersController#create as JS
2021-01-23T17:35:02.954859299Z app[web.1]: I, [2021-01-23T17:35:02.954744 #10] INFO -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] Parameters: {"authenticity_token"=>"IlDwRv3r8Qv51qXyg+roq5FiuJ+pbJjsZTlWjq50hxVKtGHptRSusL7Slf0oNiqqwN1VADhGrSbdt7GZVMp9rg==", "user"=>{"email"=>"[email protected]", "first_name"=>"", "last_name"=>"", "phone_number"=>"", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "superadmin_role"=>"0", "supervisor_role"=>"0", "user_role"=>"1"}, "commit"=>"Submit"}
2021-01-23T17:35:02.959242127Z app[web.1]: D, [2021-01-23T17:35:02.959108 #10] DEBUG -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
2021-01-23T17:35:02.964234692Z app[web.1]: D, [2021-01-23T17:35:02.964099 #10] DEBUG -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] (0.5ms) SELECT COUNT(*) FROM "stores"
2021-01-23T17:35:02.983197832Z app[web.1]: I, [2021-01-23T17:35:02.982997 #10] INFO -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] Rendering users/new.html.erb within layouts/application
2021-01-23T17:35:02.985854583Z app[web.1]: I, [2021-01-23T17:35:02.985747 #10] INFO -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] Rendered users/new.html.erb within layouts/application (Duration: 1.7ms | Allocations: 905)
2021-01-23T17:35:02.989341142Z app[web.1]: I, [2021-01-23T17:35:02.989236 #10] INFO -- : [6c93c1d9-2122-4cda-8f39-ed32e42b39e0] Completed 200 OK in 34ms (Views: 6.6ms | ActiveRecord: 1.0ms | Allocations: 4898)
===相关代码从下面开始===
路线
resources :paper_routes
get 'stores/active/' => 'stores#active'
get 'stores/inactive/' => 'stores#inactive'
resources :stores do
post :update_row_order, on: :collection
resources :sheets
collection do
match 'search' => 'stores#search', via: [:get, :post], as: :search
end
end
resources :user_managements, :controller => 'users'
devise_for :users, :skip => [:registrations], controllers: { sessions: "users/sessions", passwords: "users/passwords" }
as :user do
root 'users/sessions#new'
get 'users/edit' => 'users/registrations#edit', :as => 'edit_user_registration'
put 'user' => 'users/registrations#update', :as => 'user_registration'
end
get 'dashboard' => 'home#index', as: 'dashboard'
get 'reports' => 'reports#index', as: 'reports'
end
controllers / users_controller.rb
def new
@user = User.new
respond_to do |format|
format.html
format.json
end
end
def create
@user = User.new(user_params)
if @user.save
flash[:notice] = 'User created'
redirect_to user_managements_path and return
else
flash.now[:warning] = 'There were problems when trying to create a new User'
render :action => :new
end
end
def edit
@user = User.find params[:id]
respond_to do |format|
format.html
format.json
end
end
def update
@user = User.find params[:id]
if @user.update_attributes user_params
flash[:notice] = 'User has been updated'
redirect_to user_managements_path and return
else
flash.now[:warning] = 'There were problems when trying to update this User'
render :action => :edit
end
end
(...)
def user_params
params.require(:user).permit(:id, :email, :password, :password_confirmation, :superadmin_role, :supervisor_role, :user_role, :first_name, :last_name, :phone_number)
end
/views/users/new.html.erb
<%= form_with model: @user, url: user_managements_path, class: "form-group" do |f| %>
<div class="row pt-3">
<div class="col-sm-12 col-md-4">
<div class="field">
<%= label_tag(:name, "Email") %>
<%= f.text_field :email, :class => "form-control", :type => "text" %>
</div>
</div>
</div>
(...)
/views/users/edit.html.erb
<%= form_with model: @user, url: user_management_path(@user), class: "form-group" do |f| %>
<div class="row pt-3">
<div class="col-sm-12 col-md-4">
<div class="field">
<%= label_tag(:name, "Email") %>
<%= f.text_field :email, :class => "form-control", :type => "text" %>
</div>
</div>
</div>
(...)
如果有人对为什么这种方法在开发中起作用而不在生产中起作用有任何见解,我很想知道。似乎与不先加载Devise有关。
route.rb中的原始代码:
resources :user_managements, :controller => 'users'
devise_for :users, :skip => [:registrations], controllers: { sessions: "users/sessions", passwords: "users/passwords" }
我将订单切换为:
devise_for :users, :skip => [:registrations], controllers: { sessions: "users/sessions", passwords: "users/passwords" }
resources :user_managements, :controller => 'users'
解决了问题。再次感谢您,@ idmean,@ arieljuod,@ max和@jim!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句