使用的手机号码,而不是使用设备的默认电子邮件 [英] Using mobile number instead of using the default email in device

查看:110
本文介绍了使用的手机号码,而不是使用设备的默认电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的红宝石我试图教我观看了一些教程Ruby on Rails的。

上周,我来了解设备我尝试过,但有什么办法,以默认的电子邮件属性更改为类似手机号码。

我希望这是可能的我来很多事情的横但没有什么真正的帮助。

我希望帮助。先谢谢了。

new.html.erb登记

 < D​​IV CLASS =行垂直偏移-100>
      < D​​IV CLASS =COL-MD-4 COL-MD-偏移4>
< D​​IV CLASS =行>
  < D​​IV CLASS =span4>
  <%= simple_form_for(资源:如=> RESOURCE_NAME,:URL => session_path(RESOURCE_NAME),HTML:{类:井})做| F | %GT;    <&字段集GT;
      < H1类=TEXT-中心登录标题>获得完全免费<!/ H1>
      <%= f.input:FIRST_NAME,占位符:什么是你真棒名字? %GT;
      <%= f.input:姓氏,占位符:'和你的美丽的温馨姓'%GT;
      <%= f.input:PHONE_NUMBER,占位符:'数'%GT;
      <%= f.input:密码,占位符:制作Strengthfull密码%GT;
      <%= f.input:password_confirmation,占位符:制作Strengthfull密码%GT;
          < D​​IV><%= f.button:提交,戴尔(前进之)!等级:BTN BTN-LG BTN-信息BTN-块%>< / DIV>
      <%结束%GT;
      <%=呈现设计/共享/链接%GT;
          <脚本类型=文/ JavaScript的SRC =/资产/ jquery.backstretch.min.js>< / SCRIPT>
    <脚本>
        $ .backstretch(/资产/ shifting.jpg,{速度:500});
    < / SCRIPT>

new.html.erb的会话

 < D​​IV CLASS =行垂直偏移-100>
      < D​​IV CLASS =COL-MD-4 COL-MD-偏移4>
< D​​IV CLASS =行>
  < D​​IV CLASS =span4>
  <%= simple_form_for(资源:如=> RESOURCE_NAME,:URL => session_path(RESOURCE_NAME),HTML:{类:井})做| F | %GT;    <&字段集GT;
      < H1类=TEXT-中心登录标题>获得在使用< / H1>
    <%= f.input:PHONE_NUMBER,占位符:电话号码%GT;
    <%= f.input:密码,占位符:'密码'%GT;
    <如果devise_mapping.rememberable%? - %GT;
      < D​​IV><%= f.input:remember_me,如:布尔%GT;< / DIV>
    <%结束 - %GT;    < D​​IV><%= f.button:提交,只需登录!等级:BTN BTN-LG BTN-信息BTN-块%GT;< / DIV>
      <%结束%GT;
      &所述p为H.;
&所述; / P>
              < D​​IV CLASS =TEXT-中心>
          <% - 如果devise_mapping.recoverable? &功放;&安培; CONTROLLER_NAME ='密码'和;!&安培; CONTROLLER_NAME ='注册'%&GT!;
  <%=的link_to忘记密码?,new_password_path(RESOURCE_NAME)%GT;< BR />
<%结束 - %GT;
&所述p为H.;
&所述; / P>
<% - 如果devise_mapping.registerable? &功放;&安培; CONTROLLER_NAME ='注册'%&GT!;
  <%=的link_to立即注册,new_registration_path(RESOURCE_NAME)%GT;< BR />
<%结束 - %GT;
      < /字段集>
  < / DIV>
< / DIV>
< / DIV>
< / DIV>
    <脚本类型=文/ JavaScript的SRC =/资产/ jquery.backstretch.min.js>< / SCRIPT>
    <脚本>
        $ .backstretch(/资产/ bg.jpg,{速度:500});
    < / SCRIPT>

devise.rb

  Devise.setup做|配置|
  config.secret_key = 'e8406bef31a2c5607f3ab4eb0d165f5745a03fca20a9fa7baedd70bc3ffdec638376dda3ac58efb35dbcbaa955b897dcd5519d7458527955af6e9e8d6c9fafb6'  config.mailer_sender ='please-change-me-at-config-initializers-devise@example.com  要求设计/ ORM / active_record  config.authentication_keys = [:PHONE_NUMBER]

user.rb

 类用户< ActiveRecord的::基地
  #包括默认色器件模块。可用其他是:
  #:可确定,:可锁定,:timeoutable和:omniauthable
  设计:database_authenticatable,:可注册,
         :可恢复的,:rememberable,:可追踪,:可验证
         的has_many:出货
         的has_many:评论         高清FULL_NAME
          FIRST_NAME ++姓氏
        结束
         高清email_required?
          假
        结束
     结束

registration_controller

 类RegistrationsController<设计:: RegistrationsController
 私人的  高清sign_up_params
    params.require(:用户).permit(:FIRST_NAME,:姓氏,电话号码:PHONE_NUMBER,:密码:password_confirmation)
  结束  高清account_update_params
    params.require(:用户).permit(:FIRST_NAME,:姓氏,电话号码:PHONE_NUMBER,:密码:password_confirmation,:current_password)
  结束
结束


解决方案

这是你如何做到这一点。您需要添加以下code在配置/初始化/ devise.rb

  Devise.setup做|配置|
  config.secret_key =无论是你的秘密钥匙
  config.authentication_keys = [:PHONE_NUMBER]
结束

在你的登录的意见必须添加以下 text_field ,而不是像这样的电子邮件领域 -

 <%= f.text_field:PHONE_NUMBER,:类=> ,你的类的名称:占位符=> 电话号码%>

在这一步按照此<一个href=\"http://stackoverflow.com/questions/17021367/how-to-disable-email-validation-in-rails-device\">How禁止在轨设备电子邮件验证。

添加到您的 registration_controller ,而不是你写的是什么:

 的before_filter:configure_permitted_pa​​rameters保护高清configure_permitted_pa​​rameters
  devise_parameter_sanitizer.for(:sign_up)做| U |
    u.permit(:FIRST_NAME,:姓氏,电话号码:PHONE_NUMBER,:密码:password_confirmation)
  结束  devise_parameter_sanitizer.for(:account_update的)做| U |
    u.permit(:FIRST_NAME,:姓氏,电话号码:PHONE_NUMBER,:密码:password_confirmation)
  结束
结束

这就是它

I am new to ruby am trying to teach myself ruby on rails by watching some tutorial.

Last week I came to know about device I tried it but is there any way to change the default email attribute to something like mobile numbers.

I hope it is possible I came a cross of lots of things but there was nothing really helpful.

I hope for help. Thanks in advance.

new.html.erb-registration

<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]

user.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

registration_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

解决方案

This is how you can do it. You need to add the following code in config/initializers/devise.rb:

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

In your login views you have to add the following text_field instead of the email field like this -

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

After this step follow this How to disable email validation in rails device .

Add this to your registration_controller instead of what you have written:

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

That's it

这篇关于使用的手机号码,而不是使用设备的默认电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆