Ruby on rails 在注册时,若电子邮件已经存在,那个么在特定页面上呈现用户,在那个里我可以显示一些消息
如果电子邮件已经存在,我只想再次向用户发送确认说明 这就是我实现的,如果电子邮件是唯一的,它只允许用户注册。如果电子邮件已经存在,它就什么都不做Ruby on rails 在注册时,若电子邮件已经存在,那个么在特定页面上呈现用户,在那个里我可以显示一些消息,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 4,如果电子邮件已经存在,我只想再次向用户发送确认说明 这就是我实现的,如果电子邮件是唯一的,它只允许用户注册。如果电子邮件已经存在,它就什么都不做 class RegistrationsController < Devise::RegistrationsController layout 'pages' def new build_resource yield resource if block_given? respond_with resource e
class RegistrationsController < Devise::RegistrationsController
layout 'pages'
def new
build_resource
yield resource if block_given?
respond_with resource
end
def create
build_resource(sign_up_params)
admin = User.create(first_name: "")
resource.authenticatable = admin
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: accounts_get_started_path(resource)
end
else
byebug
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
def edit
super
end
def update
super
end
def destroy
super
end
end
类注册控制器
如果电子邮件已经存在,您应该通过以下操作重新发送确认邮件:
Devise::Mailer.confirmation_instructions(resource).deliver
如果电子邮件已存在,您应通过以下操作重新发送确认邮件:
Devise::Mailer.confirmation_instructions(resource).deliver
您可以使用valid?在指定的上下文中运行所有验证。如果未找到错误,则返回true,否则返回false。(有关更多信息,请参阅此。) 注意:这里我假设您在电子邮件字段上有唯一性验证。(有关更多信息,请参阅此) 如果您进行了验证,那么您的代码如下所示
def create
build_resource(sign_up_params)
.
.
if resource.valid?
# your code for saving details
else
# Your code to redirct to different page
redirect_to where_you_want
end
end
您可以使用valid?在指定的上下文中运行所有验证。如果未找到错误,则返回true,否则返回false。(有关更多信息,请参阅此。) 注意:这里我假设您在电子邮件字段上有唯一性验证。(有关更多信息,请参阅此) 如果您进行了验证,那么您的代码如下所示
def create
build_resource(sign_up_params)
.
.
if resource.valid?
# your code for saving details
else
# Your code to redirct to different page
redirect_to where_you_want
end
end
有人可以帮我吗?你可以使用
资源。有效吗?
它将与用户相同。有效吗?@sk1712你能不能在我的代码中以代码的形式再解释一点,在哪里以及我应该使用什么来获得结果?@sk1712指南在这里请???有人可以帮我吗?你可以使用资源。有效吗?
它将是相同的作为user.valid?@sk1712能否请您在我的代码中以代码形式再解释一点,在哪里以及我应该使用什么来获得结果?@sk1712指南,请在这里???