Apologizes if this question is too general. I am relatively new to Rails and the development in general. I am creating a Rails application that uses Twilio verification for SMS. Users register in the application using their name and phone number. This phone number is then verified using a pin delivered via SMS. I find it difficult to determine whether it will be easier and / or better to use the phone_number model, and then create a connection between users and phone_numbers using belongs_to: and has_one: or if I can make the phone number part of the User model.
I am using Rails 4.2.1
Here is my user model:
class User < ActiveRecord::Base has_secure_password validates_presence_of :name validates_presence_of :phone_number validates_uniqueness_of :phone_number end
User Controller:
class UsersController < ApplicationController def new @user = User.new end def create @user = User.new(user_params) if @user.save session[:user_id] = @user.id redirect_to root_url, notice: "Saved" else render 'new' end end private def user_params params.require(:user).permit(:name, :phone_number, :password, :password_confirmation) end end
This is the Twilio tutorial I'm trying to do:
http://twilioinc.wpengine.com/2015/06/sms-phone-verification-in-rails-4-using-ajax-and-twilio.html
Can I say this? Is the user really just a phone number with a name?
If I need to create a model / phone number controller, how do I change my routes? And how will this change my registration page, which now includes the following:
<div class="field"> <%= f.label :phone_number %><br /> <%= f.text_field :phone_number %> </div>
source share