Ruby on rails 4 rails在if语句中设计了错误数量的参数
在下面的代码中,我试图检查是否所有当前用户字段都已填充,如果未填充,请采取步骤修复该问题Ruby on rails 4 rails在if语句中设计了错误数量的参数,ruby-on-rails-4,if-statement,devise,Ruby On Rails 4,If Statement,Devise,在下面的代码中,我试图检查是否所有当前用户字段都已填充,如果未填充,请采取步骤修复该问题 class ApplicationController < ActionController::Base before_action :configure_premitted_parameters, if: :devise_controller? before_action :authenticate_user! before_action :check_status # P
class ApplicationController < ActionController::Base
before_action :configure_premitted_parameters, if: :devise_controller?
before_action :authenticate_user!
before_action :check_status
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
private
def configure_premitted_parameters
devise_parameter_sanitizer.for(:sign_in) << [:email, :password]
devise_parameter_sanitizer.for(:sign_up) << [:email, :password, :password_confirmation]
devise_parameter_sanitizer.for(:account_update) << [:email, :age, :gender, :fullname, :familyStatus, :about, :current_password, :new_password, :new_password_confirmation]
end
def check_status
if current_user(:age || :gender || :fullname || :familyStatus || :about ).empty?
redirect_to edit_user_password
else
redirect_to root_path
end
end
end
从线路
如果当前用户(:年龄| | |:性别| |:全名| |:家庭状态)||
:空的
你能解释一下我做错了什么吗?我不熟悉check\u status方法中if语句中使用的语法。假设你得到了一个参数错误,这是唯一的if语句,它接受了一个参数,我猜这是令人不快的 我倾向于将那个大的if子句转移到另一种方法中,它能更好地传达您的意图。你到底想用if语句检查什么?如果您想检查所有这些字段是否都已完成,那么下面的操作就可以了
def check_status
if current_user_incomplete?
redirect_to edit_user_password
else
redirect_to root_path
end
end
def incomplete_current_user?
[current_user.age, current_user.gender, current_user.fullname, current_user.familyStatus, current_user.about].all?
end
下次发布时,请提供有关错误的更多具体信息,例如,哪一行导致了错误。谢谢你,它起作用了,下次我会发布更多信息。关于模糊,很抱歉,但感谢你的帮助:)由于某些原因,它没有重定向。我修复了它。所有吗?出席,出席?
def check_status
if current_user_incomplete?
redirect_to edit_user_password
else
redirect_to root_path
end
end
def incomplete_current_user?
[current_user.age, current_user.gender, current_user.fullname, current_user.familyStatus, current_user.about].all?
end