gpt4 book ai didi

ruby-on-rails - 使用手机号码而不是使用设备中的默认电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:37 24 4
gpt4 key购买 nike

我是 ruby​​ 的新手,我正在尝试通过观看一些教程自学 ruby​​ on rails。

上周我开始了解我尝试过的设备,但是有什么方法可以将默认电子邮件属性更改为手机号码之类的东西。

我希望我有可能遇到很多事情,但没有什么真正有用的。

希望得到帮助。提前致谢。

new.html.erb-注册

<div class="row vertical-offset-100">
<div class="col-md-4 col-md-offset-4">
<div class="row">
<div class="span4">
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {class: "well"}) do |f| %>

<fieldset>
<h1 class="text-center login-title">Get In It's Free!</h1>
<%= f.input :first_name, placeholder: "What's Your Awesome Name?" %>
<%= f.input :last_name, placeholder: 'And Your Beutiful Last Name' %>
<%= f.input :phone_number, placeholder: 'number' %>
<%= f.input :password, placeholder: 'Make A Strengthfull Password' %>
<%= f.input :password_confirmation, placeholder: 'Make A Strengthfull Password' %>
<div><%= f.button :submit, "Dale! (Go Ahead)", class: "btn btn-lg btn-info btn-block" %></div>
<% end %>
<%= render "devise/shared/links" %>
<script type="text/javascript" src="/assets/jquery.backstretch.min.js"></script>
<script>
$.backstretch("/assets/shifting.jpg", {speed: 500});
</script>

new.html.erb-sessions

<div class="row vertical-offset-100">
<div class="col-md-4 col-md-offset-4">
<div class="row">
<div class="span4">
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {class: "well"}) do |f| %>

<fieldset>
<h1 class="text-center login-title">Get In With Your</h1>
<%= f.input :phone_number, placeholder: 'Phone Number' %>
<%= f.input :password, placeholder: 'Password' %>


<% if devise_mapping.rememberable? -%>
<div><%= f.input :remember_me, as: :boolean %></div>
<% end -%>

<div><%= f.button :submit, "Just Sign In!", class: "btn btn-lg btn-info btn-block" %></div>
<% end %>
<p>
</p>
<div class="text-center">
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<p>
</p>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up Now", new_registration_path(resource_name) %><br />
<% end -%>
</fieldset>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="/assets/jquery.backstretch.min.js"></script>
<script>
$.backstretch("/assets/bg.jpg", {speed: 500});
</script>

devise.rb

Devise.setup do |config|
config.secret_key = 'e8406bef31a2c5607f3ab4eb0d165f5745a03fca20a9fa7baedd70bc3ffdec638376dda3ac58efb35dbcbaa955b897dcd5519d7458527955af6e9e8d6c9fafb6'

config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'

require 'devise/orm/active_record'

config.authentication_keys = [:phone_number]

用户.rb

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :shipments
has_many :comments

def full_name
first_name + " " + last_name
end
def email_required?
false
end
end

注册 Controller

class RegistrationsController < Devise::RegistrationsController
private

def sign_up_params
params.require(:user).permit(:first_name, :last_name, :phone_number, :password, :password_confirmation)
end

def account_update_params
params.require(:user).permit(:first_name, :last_name, :phone_number, :password, :password_confirmation, :current_password)
end
end

最佳答案

这就是您可以做到的。您需要在config/initializers/devise.rb中添加如下代码:

Devise.setup do |config|
config.secret_key = "Whatever is your secret key"
config.authentication_keys = [ :phone_number ]
end

在您的 login View 中,您必须添加以下 text_field 而不是像这样的电子邮件字段 -

<%= f.text_field :phone_number, :class => 'Name of your class', :placeholder => "Phone Number" %>  

完成此步骤后,请执行此 How to disable email validation in rails device .

将此添加到您的 registration_controller 而不是您编写的内容:

before_filter :configure_permitted_parameters

protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:first_name, :last_name, :phone_number, :password, :password_confirmation)
end

devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:first_name, :last_name, :phone_number, :password, :password_confirmation)
end
end

就是这样

关于ruby-on-rails - 使用手机号码而不是使用设备中的默认电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31402289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com