Giter Club home page Giter Club logo

has_contact_number's Introduction

HasContactNumber

Provides support for validating, storing and retrieving phone, mobile, fax numbers with ISD code.

Installation

Add this line to your application's Gemfile:

gem 'has_contact_number'

And then execute:

    $ bundle

Usage

Prerequisites

Add columns for required contact_number attributes in table.

In Model

Define contact number attributes/columns in model where you have columns like phone_number, mobile_number, fax_number, etc.

contact_number_attributes :column1, :column2, :columnN

For example:

class Contact < ActiveRecord::Base

  contact_number_attributes :phone_number, :mobile_number, :fax_number

end

In Controller

Use method contact_number_attributes to generate list of attributes to be permitted.

For example:

class ContactsController < ApplicationController

  def contact_params
    params.require(:contact).permit(
      *contact_number_attributes(:phone_number, :mobile_number, :fax_number), # Other attributes
    )
  end

end

Note: Pay attention to usage of splat operator (*) prefixed to contact_number_attributes

In View

You can add select list for ISD code of contact_number attribute using collection options_for_isd_code_select and text field for contact_number attribute.

For example: If you have phone_number attribute then following should be your view code (For HAML)

= f.select :phone_number_isd_code, options_for_isd_code_select, prompt: 'Select'
= f.text_field :phone_number_without_isd_code, placeholder: 'Phone Number'

You can use any FormBuilder like SimpleForm as

= f.input :phone_number_isd_code, collection: options_for_isd_code_select, prompt: 'Select'
= f.input :phone_number_without_isd_code, placeholder: 'Phone Number'

TODOs

  • Helper methods for generating fields on view
  • Field helper methods with Bootstrap, Foundation support
  • Method to format contact number as per default pattern
  • Method to format contact number as per country of ISD code
  • Method to format number as per custom pattern passed

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/has_contact_number. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

has_contact_number's People

Contributors

anandbait avatar aquistech avatar

Watchers

 avatar  avatar  avatar

has_contact_number's Issues

Not working with Rails 6

Not working with Rails 6 and possibly may not work with Rails 5

ArgumentError (Passing string to be evaluated in :if and :unless conditional options is not supported. Pass a symbol for an instance method, or a lambda, proc or block, instead.):
  
(eval):15:in `define_methods_for'

Full trace

(eval):15:in `define_methods_for'
/home/anand/projects/has_contact_number/lib/has_contact_number/model_methods.rb:16:in `class_eval'
/home/anand/projects/has_contact_number/lib/has_contact_number/model_methods.rb:16:in `define_methods_for'
/home/anand/projects/has_contact_number/lib/has_contact_number/model_methods.rb:10:in `block in contact_number_attributes'
/home/anand/projects/has_contact_number/lib/has_contact_number/model_methods.rb:8:in `each'
/home/anand/projects/has_contact_number/lib/has_contact_number/model_methods.rb:8:in `contact_number_attributes'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.