ruby on rails - Using mobile number instead of using the default email in device -
i new ruby trying teach myself ruby on rails watching tutorial.
last week came know device tried there way change default email attribute mobile numbers.
i hope possible came cross of lots of things there nothing helpful.
i hope help. 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"}) |f| %> <fieldset> <h1 class="text-center login-title">get in it's free!</h1> <%= f.input :first_name, placeholder: "what's awesome name?" %> <%= f.input :last_name, placeholder: 'and beutiful last name' %> <%= f.input :phone_number, placeholder: 'number' %> <%= f.input :password, placeholder: 'make strengthfull password' %> <%= f.input :password_confirmation, placeholder: 'make 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"}) |f| %> <fieldset> <h1 class="text-center login-title">get in 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 password?", new_password_path(resource_name) %><br /> <% end -%> <p> </p> <%- if devise_mapping.registerable? && controller_name != 'registrations' %> <%= link_to "sign 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 |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 , :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 how can it. need add following code in config/initializers/devise.rb
:
devise.setup |config| config.secret_key = "whatever secret key" config.authentication_keys = [ :phone_number ] end
in login
views have add following text_field
instead of email field -
<%= f.text_field :phone_number, :class => 'name of class', :placeholder => "phone number" %>
after step follow how disable email validation in rails device .
add registration_controller instead of have written:
before_filter :configure_permitted_parameters protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) |u| u.permit(:first_name, :last_name, :phone_number, :password, :password_confirmation) end devise_parameter_sanitizer.for(:account_update) |u| u.permit(:first_name, :last_name, :phone_number, :password, :password_confirmation) end end
that's it
Comments
Post a Comment