[英]param is missing or the value is empty: user when enabling password access to a page in Rails app
I am getting this error: "param is missing or the value is empty: user" when I am trying to create password restricted access to user settings page in my app.当我尝试在我的应用程序中创建对用户设置页面的密码限制访问时,我收到此错误:“参数丢失或值为空:用户”。 All the logged in users can see a tab to change their two factor settings page.
所有登录的用户都可以看到一个选项卡来更改他们的两个因素设置页面。 When they are click on the tab for two factor settings, they are required to enter the password for that account.
当他们单击两个因素设置的选项卡时,他们需要输入该帐户的密码。 I have a created page for password entry.
我有一个用于输入密码的创建页面。 However I keep getting the above error.
但是我不断收到上述错误。
Here is the controller method defined inside two_factor_settings_controller.rb这是在 two_factor_settings_controller.rb 中定义的 controller 方法
def authorization_check_for_2fa
@user = current_user
prompt_for_password(current_user)
if authorization_check_params[:password].present?
debugger
if current_user.valid_password?(authorization_check_params[:password])
flash.now[:success] = "Yay correct password"
redirect_to two_factor_settings_path
else
flash.now[:alert] = "Sorry, wrong password"
end
end
end
And these are the private methods in the controller:这些是 controller 中的私有方法:
def prompt_for_password(user)
@user = user
session[:otp_user_id] = user.id
render authorization_check_for_2fa_two_factor_settings_path
end
def authorization_check_params
params.require(:user).permit(:password)
end
The view page looks like this:视图页面如下所示:
.card.mb-3
.card-header
%h5.mb-0 Restricted access
.card-body
= simple_form_for @user, url: authorization_check_for_2fa_two_factor_settings_path, html: { method: :post } do |f|
.form-inputs
= f.input :password, input_html: { autocomplete: "current-password" }, required: true
.form-actions
= submit_button 'Submit', class: 'btn btn-primary'
Inside the route file:在路由文件中:
resource :two_factor_settings do
get :authorization_check_for_2fa, on: :member
post :authorization_check_for_2fa, on: :member
get :regenerate_backup_codes, on: :member
end
Would appreciate any clue to what is causing this error.将不胜感激导致此错误的任何线索。 thanks
谢谢
According to the documentation of simple_form , here is what your form should look like:根据simple_form的文档,您的表单应如下所示:
<%= simple_form_for(@user, as: :user, method: :post, url: users_path) do |f| %>
<%= f.input :name %>
<%= f.submit 'New user' %>
<% end %>
The most important part in your case is f.submit 'New user'
.在您的案例中,最重要的部分是
f.submit 'New user'
。 You're submitting your form outside the form of the gem.您在 gem 表单之外提交表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.