-
-
Save marocchino/8817691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A < ActiveRecord::Base | |
validates :phoneNum1, numericality: { only_integer: true } | |
validates :phoneNum2, numericality: { only_integer: true } | |
validates :phoneNum3, numericality: { only_integer: true } | |
def phoneNum1 | |
phoneNum && phoneNum.split("-")[0] | |
end | |
def phoneNum2 | |
phoneNum && phoneNum.split("-")[1] | |
end | |
def phoneNum3 | |
phoneNum && phoneNum.split("-")[2] | |
end | |
def phoneNum1=(phoneNum1) | |
@phoneNum1 = phoneNum1 | |
set_phoneNum | |
end | |
def phoneNum2=(phoneNum3) | |
@phoneNum2 = phoneNum3 | |
set_phoneNum | |
end | |
def phoneNum3=(phoneNum3) | |
@phoneNum3 = phoneNum3 | |
set_phoneNum | |
end | |
private | |
def set_phoneNum | |
if @phoneNum1 && @phoneNum2 && @phoneNum3 | |
self.phoneNum = "#{@phoneNum1}-#{@phoneNum2}-#{@phoneNum3}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A < ActiveRecord::Base | |
validates :phoneNum, ... | |
end | |
class AController < ApplicationController | |
def create | |
A.create(a_params) | |
end | |
private | |
def a_params | |
params[:a][:phoneNum] = "#{params[:a][:phoneNum1]}-#{params[:a][:phoneNum2]}-#{params[:a][:phoneNum3]}" | |
params[:a].permit(...) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment