Ruby on rails 如何添加自定义设计错误消息?
我有这样一个代码,如果一个用户使用与以前相同的电子邮件注册了Facebook,我们将阻止该用户再次注册。相反,我们会提示他们登录facebook。我们想创建一个定制的Ruby on rails 如何添加自定义设计错误消息?,ruby-on-rails,devise,Ruby On Rails,Devise,我有这样一个代码,如果一个用户使用与以前相同的电子邮件注册了Facebook,我们将阻止该用户再次注册。相反,我们会提示他们登录facebook。我们想创建一个定制的资源。errors来说明这个场景。实现它的最佳方法是什么?首先,我认为您在respond\u to中有一个错误,因为总是执行相同的操作。您必须在if子句resource.errors.add(:email,“您的电子邮件已被占用,请使用Facebook登录”)或重定向到:新建会话路径,闪烁:“您的…”并返回 def create
资源。errors
来说明这个场景。实现它的最佳方法是什么?首先,我认为您在respond\u to
中有一个错误,因为总是执行相同的操作。您必须在if
子句resource.errors.add(:email,“您的电子邮件已被占用,请使用Facebook登录”)
或重定向到:新建会话路径,闪烁:“您的…”并返回
def create
build_resource(sign_up_params.select{|k,v| v.present?})
if Identity.identity_exists?(resource.email)
# Prompt user to sign in with Facebook instead
puts 'prompt user to sign in with facebook'
else
if resource.save
# redirect_to_signup_finish / return ?
else
clean_up_passwords resource
end
end
respond_to do |format|
format.html { render :new }
format.json { render :json => { errors: resource.errors }, :status => :unprocessable_entity }
end
end