Skip to content

sazwqa/implements_phone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

=== Implements Phone

Implements Phone provides helpers at model and view level to add phone numbers with ease.

=== Using in model

Add the following in your model

implements_phone
    
Options:

fields              Tell the fields that should be used for storing phone (better be string).
validate_presence   Tell the fields on which you want to apply validates_presence_of. (default is none)
format_message      Message to be displayed if phone number is in improper format. (default is 'is in improper format.')
presence_message    Message to be displayed if phone number is empty. (default is 'is blank.')
format_regex        Regex against with phone numbers shall be evaluated. (default is /^([0-9]){3}\-([0-9]){3}\-([0-9]){4}([\-]){0,1}([0-9]){0,4}$/)

When you write implements_phone in your model (for a field phone), 
you get the following methods:

phone_apart
phone_apart=
formatted_phone

phone_apart accessor is used to get/set values for the phone field.
formatted_phone gives phone formatted for use in views, like:

321-321-3213 Ext. 3213

=== Using in view

You get a helper +phone_field+ for use in view. Use it as follows:

<%= phone_field(@user, :phone_field) %>

Here as evident the first parameter is the object of the model on which implements_phone is used 
and second paramter is the name of the phone field.

fieldWithErrors is added to phone fields if they contain any errors, you will need to style them accordingly.

=== Bugs or Feedback ?
http://implements-phone.lighthouseapp.com/

About

Helpers to assist in adding phone numbers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages