1659233580
Phonelib is a gem allowing you to validate phone number. All validations are based on Google libphonenumber. Currently it can make basic validations and formatting to e164 international number format and national number format with prefix. But it still doesn't include all Google's library functionality.
In case your phone number is incorrectly parsed, you can check original libphonenumber for result here and in case of same parse result open an issue for them. This gem's data is based on it. If you can't wait for libphonenumber to resolve the issue, try to use Phonelib.add_additional_regex
and Phonelib.additional_regexes
methods.
Change log can be found in repo's releases page https://github.com/daddyz/phonelib/releases
If you discover a problem with Phonelib gem, let us know about it. https://github.com/daddyz/phonelib/issues
You can see an example of ActiveRecord validation by phonelib working in spec/dummy application of this gem
Phonelib was written and tested on Rails >= 3.1. You can install it by adding in to your Gemfile with:
gem 'phonelib'
Run the bundle command to install it.
To set the default country or several default countries for parsing (country names are ISO 3166-1 Alpha-2 codes), create a initializer in config/initializers/phonelib.rb:
Phonelib.default_country = "CN"
Phonelib.default_country = ['CN', 'FR']
To use the ability to parse special numbers (Short Codes, Emergency etc.) you can set Phonelib.parse_special
. This is disabled by default
Phonelib.parse_special = true
To allow vanity phone numbers conversion you can set Phonelib.vanity_conversion
to true
. This will convert characters in passed phone number to their numeric representation (800-CALL-NOW will be 800-225-5669).
Phonelib.vanity_conversion = true
To disable sanitizing of passed phone number (keeping digits only)
Phonelib.strict_check = true
To change sanitized symbols on parsed number, so non-specified symbols won't be wiped and will fail the parsing
Phonelib.sanitize_regex = '[\.\-\(\) \;\+]'
To disable sanitizing of double prefix on passed phone number
Phonelib.strict_double_prefix_check = true
To set different extension separator on formatting, this setting doesn't affect parsing. Default setting is ';'
Phonelib.extension_separator = ';'
To set symbols that are used for separating extension from phone number for parsing use Phonelib.extension_separate_symbols
method. Default value is '#;'. In case string is passed each one of the symbols in the string will be treated as possible separator, in case array was passed each string in array will be treated as possible separator.
Phonelib.extension_separate_symbols = '#;' # for single symbol separator
Phonelib.extension_separate_symbols = %w(ext # ; extension) # each string will be treated as separator
In case you need to overwrite some Google's libphonenumber library data, you need to assign file path to this setter. File should be Marshal.dump'ed with existing structure like in Phonelib.phone_data
. Gem is simply doing merge
between hashes.
Phonelib.override_phone_data = '/path/to/override_phone_data.dat'
In case you want to add some custom or still not updated regex patterns for certain type you can use additional regexes feature in a following way:
Phonelib.add_additional_regex :us, Phonelib::Core::MOBILE, '[5]{10}' # this will add number 1-555-555-5555 to be valid
Phonelib.add_additional_regex :gb, Phonelib::Core::MOBILE, '[1]{5}' # this will add number 44-11-111 to be valid
# you can also specify all regexes using this method
Phonelib.additional_regexes = [[:us, :mobile, "[5]{10}"], [:gb, :mobile, "[1]{5}"]]
# or just use dump method to keep them altogether
Phonelib.dump_additional_regexes # => [["US", :mobile, "[5]{10}"], ["GB", :mobile, "[1]{5}"]
(!) For a list of available types refer to this readme.
(!) Please note that regex should be added as string
In case phone number that was passed for parsing has "+" sign in the beginning, library will try to detect a country regarding the provided one.
This gem adds validator for active record. Basic usage:
validates :attribute, phone: true
This will enable Phonelib validator for field "attribute". This validator checks that passed value is valid phone number. Please note that passing blank value also fails.
Additional options:
validates :attribute, phone: { possible: true, allow_blank: true, types: [:voip, :mobile], country_specifier: -> phone { phone.country.try(:upcase) } }
possible: true - enables validation to check whether the passed number is a possible phone number (not strict check). Refer to Google libphonenumber for more information on it.
allow_blank: true - when no value passed then validation passes
types: :mobile or types: [:voip, :mobile] - allows to validate against specific phone types patterns, if mixed with possible will check if number is possible for specified type
countries: :us or countries: [:us, :ca] - allows to validate against specific countries, if mixed with possible will check if number is possible for specified countries
country_specifier: :method_name or country_specifier: -> instance { instance.country.try(:upcase) } - allows to specify country for validation dynamically for each validation. Usefull when phone is stored as national number without country prefix.
extensions: false - set to perform check for phone extension to be blank
To check if phone number is valid simply run:
Phonelib.valid?('123456789') # returns true or false
Additional methods:
Phonelib.valid? '123456789' # checks if passed value is valid number
Phonelib.invalid? '123456789' # checks if passed value is invalid number
Phonelib.possible? '123456789' # checks if passed value is possible number
Phonelib.impossible? '123456789' # checks if passed value is impossible number
There is also option to check if provided phone is valid for specified country. Country should be specified as two letters country code (like "US" for United States). Country can be specified as String 'US' or 'us' as well as symbol :us.
Phonelib.valid_for_country? '123456789', 'XX' # checks if passed value is valid number for specified country
Phonelib.invalid_for_country? '123456789', 'XX' # checks if passed value is invalid number for specified country
Additionally you can run:
phone = Phonelib.parse('123456789')
phone = Phonelib.parse('+1 (972) 123-4567', 'US')
You can pass phone number with extension, it should be separated with ; or # signs from the phone number.
Returned value is object of Phonelib::Phone class which have following methods:
# basic validation methods
phone.valid?
phone.invalid?
phone.possible?
phone.impossible?
# validations for countries
phone.valid_for_country? 'XX'
phone.invalid_for_country? 'XX'
You can also fetch matched valid phone types
phone.types # returns array of all valid types
phone.type # returns first element from array of all valid types
phone.possible_types # returns array of all possible types
Possible types:
Or you can get human representation of matched types
phone.human_types # return array of human representations of valid types
phone.human_type # return human representation of first valid type
Also you can fetch all matched countries
phone.countries # returns array of all matched countries
phone.country # returns first element from array of all matched countries
phone.valid_countries # returns array of countries where phone was matched against valid pattern
phone.valid_country # returns first valid country from array of valid countries
phone.country_code # returns country phone prefix
Also it is possible to get formatted phone number
phone.international # returns formatted e164 international phone number
phone.national # returns formatted national number with national prefix
phone.area_code # returns area code of parsed number or nil
phone.local_number # returns local number
phone.extension # returns extension provided with phone
phone.full_e164 # returns e164 phone representation with extension
phone.full_international # returns formatted international number with extension
You can pass false to national and international methods in order to get unformatted representations
phone.international(false) # returns unformatted international phone
phone.national(false) # returns unformatted national phone
You can get E164 formatted number
phone.e164 # returns number in E164 format
You can define prefix for international
and e164
related methods to get formatted number prefixed with anything you need.
phone.international('00') # returns formatted international number prefixed by 00 instead of +
phone.e164('00') # returns e164 represantation of a number prefixed by 00 instead of +
phone.full_international('00') # returns formatted international number with extension prefixed by 00 instead of +
phone.full_e164('00') # returns e164 represantation of a number with extension prefixed by 00 instead of +
phone.international_00 # same as phone.international('00'). 00 can be replaced with whatever you need
phone.e164_00 # same as phone.international('00')
There is a to_s
method, it will return e164
in case number is valid and original
otherwise
phone.to_s # returns number in E164 format if number is valid or original otherwise
You can compare 2 instances of Phonelib::Phone
with ==
method or just use it with string
phone1 = Phonelib.parse('+12125551234') # Phonelib::Phone instance
phone2 = Phonelib.parse('+12125551234') # Phonelib::Phone instance
phone1 == phone2 # returns true
phone1 == '+12125551234' # returns true
phone1 == '12125551234;123' # returns true
There is extended data available for numbers. It will return nil in case there is no data or phone is impossible. Can return array of values in case there are some results for specified number
phone.geo_name # returns geo name of parsed phone
phone.timezone # returns timezone name of parsed phone
phone.carrier # returns carrier name of parsed phone
Phone class has following attributes
phone.original # string that was passed as phone number
phone.sanitized # sanitized phone number (only digits left)
Gem includes data from Google libphonenumber which has regex patterns for validations. Valid patterns are more specific to phone type and country. Possible patterns as usual are patterns with number of digits in number.
Everyone can do whatever he wants, the only limit is your imagination. Just don't forget to write test before the pull request. In order to run test without Rails functionality simply use
bundle exec rake spec
If you want to run including Rails environment, you need to set BUNDLE_GEMFILE while running the spec task, for example:
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.2.x bundle exec rake spec
Gemfiles can be found in gemfiles folder, there are gemfiles for Rails 3.1, 3.2, 4, 5 and 5.1.
Author: daddyz
Source code: https://github.com/daddyz/phonelib
License: MIT license
1594769515
Data validation and sanitization is a very important thing from security point of view for a web application. We can not rely on user’s input. In this article i will let you know how to validate mobile phone number in laravel with some examples.
if we take some user’s information in our application, so usually we take phone number too. And if validation on the mobile number field is not done, a user can put anything in the mobile number field and without genuine phone number, this data would be useless.
Since we know that mobile number can not be an alpha numeric or any alphabates aand also it should be 10 digit number. So here in this examples we will add 10 digit number validation in laravel application.
We will aalso see the uses of regex in the validation of mobile number. So let’s do it with two different way in two examples.
In this first example we will write phone number validation in HomeController where we will processs user’s data.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('createUser');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'phone' => 'required|digits:10',
'email' => 'required|email|unique:users'
]);
$input = $request->all();
$user = User::create($input);
return back()->with('success', 'User created successfully.');
}
}
In this second example, we will use regex for user’s mobile phone number validation before storing user data in our database. Here, we will write the validation in Homecontroller like below.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Validator;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('createUser');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10',
'email' => 'required|email|unique:users'
]);
$input = $request->all();
$user = User::create($input);
return back()->with('success', 'User created successfully.');
}
}
#laravel #laravel phone number validation #laravel phone validation #laravel validation example #mobile phone validation in laravel #phone validation with regex #validate mobile in laravel
1659233580
Phonelib is a gem allowing you to validate phone number. All validations are based on Google libphonenumber. Currently it can make basic validations and formatting to e164 international number format and national number format with prefix. But it still doesn't include all Google's library functionality.
In case your phone number is incorrectly parsed, you can check original libphonenumber for result here and in case of same parse result open an issue for them. This gem's data is based on it. If you can't wait for libphonenumber to resolve the issue, try to use Phonelib.add_additional_regex
and Phonelib.additional_regexes
methods.
Change log can be found in repo's releases page https://github.com/daddyz/phonelib/releases
If you discover a problem with Phonelib gem, let us know about it. https://github.com/daddyz/phonelib/issues
You can see an example of ActiveRecord validation by phonelib working in spec/dummy application of this gem
Phonelib was written and tested on Rails >= 3.1. You can install it by adding in to your Gemfile with:
gem 'phonelib'
Run the bundle command to install it.
To set the default country or several default countries for parsing (country names are ISO 3166-1 Alpha-2 codes), create a initializer in config/initializers/phonelib.rb:
Phonelib.default_country = "CN"
Phonelib.default_country = ['CN', 'FR']
To use the ability to parse special numbers (Short Codes, Emergency etc.) you can set Phonelib.parse_special
. This is disabled by default
Phonelib.parse_special = true
To allow vanity phone numbers conversion you can set Phonelib.vanity_conversion
to true
. This will convert characters in passed phone number to their numeric representation (800-CALL-NOW will be 800-225-5669).
Phonelib.vanity_conversion = true
To disable sanitizing of passed phone number (keeping digits only)
Phonelib.strict_check = true
To change sanitized symbols on parsed number, so non-specified symbols won't be wiped and will fail the parsing
Phonelib.sanitize_regex = '[\.\-\(\) \;\+]'
To disable sanitizing of double prefix on passed phone number
Phonelib.strict_double_prefix_check = true
To set different extension separator on formatting, this setting doesn't affect parsing. Default setting is ';'
Phonelib.extension_separator = ';'
To set symbols that are used for separating extension from phone number for parsing use Phonelib.extension_separate_symbols
method. Default value is '#;'. In case string is passed each one of the symbols in the string will be treated as possible separator, in case array was passed each string in array will be treated as possible separator.
Phonelib.extension_separate_symbols = '#;' # for single symbol separator
Phonelib.extension_separate_symbols = %w(ext # ; extension) # each string will be treated as separator
In case you need to overwrite some Google's libphonenumber library data, you need to assign file path to this setter. File should be Marshal.dump'ed with existing structure like in Phonelib.phone_data
. Gem is simply doing merge
between hashes.
Phonelib.override_phone_data = '/path/to/override_phone_data.dat'
In case you want to add some custom or still not updated regex patterns for certain type you can use additional regexes feature in a following way:
Phonelib.add_additional_regex :us, Phonelib::Core::MOBILE, '[5]{10}' # this will add number 1-555-555-5555 to be valid
Phonelib.add_additional_regex :gb, Phonelib::Core::MOBILE, '[1]{5}' # this will add number 44-11-111 to be valid
# you can also specify all regexes using this method
Phonelib.additional_regexes = [[:us, :mobile, "[5]{10}"], [:gb, :mobile, "[1]{5}"]]
# or just use dump method to keep them altogether
Phonelib.dump_additional_regexes # => [["US", :mobile, "[5]{10}"], ["GB", :mobile, "[1]{5}"]
(!) For a list of available types refer to this readme.
(!) Please note that regex should be added as string
In case phone number that was passed for parsing has "+" sign in the beginning, library will try to detect a country regarding the provided one.
This gem adds validator for active record. Basic usage:
validates :attribute, phone: true
This will enable Phonelib validator for field "attribute". This validator checks that passed value is valid phone number. Please note that passing blank value also fails.
Additional options:
validates :attribute, phone: { possible: true, allow_blank: true, types: [:voip, :mobile], country_specifier: -> phone { phone.country.try(:upcase) } }
possible: true - enables validation to check whether the passed number is a possible phone number (not strict check). Refer to Google libphonenumber for more information on it.
allow_blank: true - when no value passed then validation passes
types: :mobile or types: [:voip, :mobile] - allows to validate against specific phone types patterns, if mixed with possible will check if number is possible for specified type
countries: :us or countries: [:us, :ca] - allows to validate against specific countries, if mixed with possible will check if number is possible for specified countries
country_specifier: :method_name or country_specifier: -> instance { instance.country.try(:upcase) } - allows to specify country for validation dynamically for each validation. Usefull when phone is stored as national number without country prefix.
extensions: false - set to perform check for phone extension to be blank
To check if phone number is valid simply run:
Phonelib.valid?('123456789') # returns true or false
Additional methods:
Phonelib.valid? '123456789' # checks if passed value is valid number
Phonelib.invalid? '123456789' # checks if passed value is invalid number
Phonelib.possible? '123456789' # checks if passed value is possible number
Phonelib.impossible? '123456789' # checks if passed value is impossible number
There is also option to check if provided phone is valid for specified country. Country should be specified as two letters country code (like "US" for United States). Country can be specified as String 'US' or 'us' as well as symbol :us.
Phonelib.valid_for_country? '123456789', 'XX' # checks if passed value is valid number for specified country
Phonelib.invalid_for_country? '123456789', 'XX' # checks if passed value is invalid number for specified country
Additionally you can run:
phone = Phonelib.parse('123456789')
phone = Phonelib.parse('+1 (972) 123-4567', 'US')
You can pass phone number with extension, it should be separated with ; or # signs from the phone number.
Returned value is object of Phonelib::Phone class which have following methods:
# basic validation methods
phone.valid?
phone.invalid?
phone.possible?
phone.impossible?
# validations for countries
phone.valid_for_country? 'XX'
phone.invalid_for_country? 'XX'
You can also fetch matched valid phone types
phone.types # returns array of all valid types
phone.type # returns first element from array of all valid types
phone.possible_types # returns array of all possible types
Possible types:
Or you can get human representation of matched types
phone.human_types # return array of human representations of valid types
phone.human_type # return human representation of first valid type
Also you can fetch all matched countries
phone.countries # returns array of all matched countries
phone.country # returns first element from array of all matched countries
phone.valid_countries # returns array of countries where phone was matched against valid pattern
phone.valid_country # returns first valid country from array of valid countries
phone.country_code # returns country phone prefix
Also it is possible to get formatted phone number
phone.international # returns formatted e164 international phone number
phone.national # returns formatted national number with national prefix
phone.area_code # returns area code of parsed number or nil
phone.local_number # returns local number
phone.extension # returns extension provided with phone
phone.full_e164 # returns e164 phone representation with extension
phone.full_international # returns formatted international number with extension
You can pass false to national and international methods in order to get unformatted representations
phone.international(false) # returns unformatted international phone
phone.national(false) # returns unformatted national phone
You can get E164 formatted number
phone.e164 # returns number in E164 format
You can define prefix for international
and e164
related methods to get formatted number prefixed with anything you need.
phone.international('00') # returns formatted international number prefixed by 00 instead of +
phone.e164('00') # returns e164 represantation of a number prefixed by 00 instead of +
phone.full_international('00') # returns formatted international number with extension prefixed by 00 instead of +
phone.full_e164('00') # returns e164 represantation of a number with extension prefixed by 00 instead of +
phone.international_00 # same as phone.international('00'). 00 can be replaced with whatever you need
phone.e164_00 # same as phone.international('00')
There is a to_s
method, it will return e164
in case number is valid and original
otherwise
phone.to_s # returns number in E164 format if number is valid or original otherwise
You can compare 2 instances of Phonelib::Phone
with ==
method or just use it with string
phone1 = Phonelib.parse('+12125551234') # Phonelib::Phone instance
phone2 = Phonelib.parse('+12125551234') # Phonelib::Phone instance
phone1 == phone2 # returns true
phone1 == '+12125551234' # returns true
phone1 == '12125551234;123' # returns true
There is extended data available for numbers. It will return nil in case there is no data or phone is impossible. Can return array of values in case there are some results for specified number
phone.geo_name # returns geo name of parsed phone
phone.timezone # returns timezone name of parsed phone
phone.carrier # returns carrier name of parsed phone
Phone class has following attributes
phone.original # string that was passed as phone number
phone.sanitized # sanitized phone number (only digits left)
Gem includes data from Google libphonenumber which has regex patterns for validations. Valid patterns are more specific to phone type and country. Possible patterns as usual are patterns with number of digits in number.
Everyone can do whatever he wants, the only limit is your imagination. Just don't forget to write test before the pull request. In order to run test without Rails functionality simply use
bundle exec rake spec
If you want to run including Rails environment, you need to set BUNDLE_GEMFILE while running the spec task, for example:
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.2.x bundle exec rake spec
Gemfiles can be found in gemfiles folder, there are gemfiles for Rails 3.1, 3.2, 4, 5 and 5.1.
Author: daddyz
Source code: https://github.com/daddyz/phonelib
License: MIT license
1612067550
In this small tutorial I will explain you how to validate phone number using jquery input mask, Using jquery input mask we can validate diffrent type of phone no with diffrent country code. Here, we are using jquery inputmask js for this example, so we can easily validate phone no.
This Article is Originally Published on Websolutionstuff : https://websolutionstuff.com/post/how-to-validate-phone-number-using-jquery-input-mask
<html>
<head>
<title>jquery input mask phone number validation - websolutionstuff</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/jquery.inputmask.bundle.min.js"></script>
</head>
<body>
<div class="container" style="border:1px solid red; padding: 0px 20px 20px 20px; margin-top: 20px;">
<h1>jquery input mask phone number validation - websolutionstuff.com</h1>
<br>
<strong>Phone Number:</strong>
<input type="text" name="phone" class="phone_number form-control" value="9876543210">
<br>
<strong>Phone Number:</strong>
<input type="text" name="phone" class="phone_number_2 form-control" value="9876543210">
<br>
<strong>Phone Number:</strong>
<input type="text" name="phone" class="phone_number_3 form-control" value="91 9876543210">
</div>
<script>
$(document).ready(function(){
$('.phone_number').inputmask('(999)-999-9999');
$('.phone_number_2').inputmask('(99)-9999-9999');
$('.phone_number_3').inputmask('+99-9999999999');
});
</script>
</body>
</html>
In above code i have added inputmask in jquery for diffrent validation.
You can see output in below screen print.
#javascript #jquery #validation #phone #number #input-mask
1659351660
Please create a ticket on github if you have issues. They will be addressed ASAP.
Please look at the homepage for more details. Or take a look at the github page
This is a Rails e-commerce platform. ROR Ecommerce is a Rails 5.1 application with the intent to allow developers to create an ecommerce solution easily. This solution includes an Admin for Purchase Orders, Product creation, Shipments, Fulfillment and creating Orders. There is a minimal customer facing shopping cart understanding that this will be customized. The cart allows you to track your customers' cart history and includes a double entry accounting system.
The project has Solr searching, Compass and Zurb Foundation for CSS and uses jQuery. Currently the most complete Rails solution for your small business.
Please use Ruby 2.4 and enjoy Rails 5.1.
ROR Ecommerce is designed so that if you understand Rails you will understand ROR_ecommerce. There is nothing in this project besides what you might see in a normal Rails application. If you don't like something, you are free to just change it like you would in any other Rails app.
Contributors are welcome! We will always need help with UI, documentation, and code, so feel free to pitch in. To get started, simply fork this repo, make any changes (big or small), and create a pull request.
Take a look at The Demo. The login name is test@ror-e.com with a password => test123
NOTE: Given that everyone has admin rights to the demo it is frequently looking less than "beautiful".
Please feel free to ask/answer questions in our Google Group.
Install RVM with Ruby 2.4. If you have 2.4 on your system you're good to go. Please refer to the RVM site for more details.
Copy the database.yml
for your setup. For SQLite3, cp config/database.yml.sqlite3 config/database.yml
. For MySQL, cp config/database.yml.mysql config/database.yml
and update your username/password.
If you are using the mysql dmg file to install mysql you will need to edit your ~/.bash_profile and include this:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
Install gems and build the app
gem install bundler
bundle install
rake secret # copy/paste the output as `encryption_key` in `config/settings.yml`
rake db:create:all
rake db:migrate db:seed
RAILS_ENV=test rake db:test:prepare
RAILS_ENV=test rake db:seed
Once everything is set up, start the server with rails server
and direct your web browser to localhost:3000/admin/overviews. Write down the username/password (these are only shown once) and follow the directions.
Most users are using Amazon S3 or Heroku. Thus we have decided to have a setup easy to get your site up and running as quickly as possible in this production environment. Hence you should add the following ENV variables:
FOG_DIRECTORY => your bucket on AWS
AWS_ACCESS_KEY_ID => your access key on AWS
AWS_SECRET_ACCESS_KEY => your secret key on AWS
AUTHNET_LOGIN => if you use authorize.net otherwise change config/settings.yml && config/environments/*.rb
AUTHNET_PASSWORD => if you use authorize.net otherwise change config/settings.yml && config/environments/*.rb
On linux:
export FOG_DIRECTORY=xxxxxxxxxxxxxxx
export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AUTHNET_LOGIN=xxxxxxxxxxx
export AUTHNET_PASSWORD=xxxxxxxxxxxxxxx
On Heroku:
heroku config:add FOG_DIRECTORY=xxxxxxxxxxxxxxx
heroku config:add AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxx
heroku config:add AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
heroku config:add AUTHNET_LOGIN=xxxxxxxxxxx
heroku config:add AUTHNET_PASSWORD=xxxxxxxxxxxxxxx
heroku labs:enable user-env-compile -a myapp
This is needed for using sendgrid on heroku(config/initializers/mail.rb):
heroku config:add SENDGRID_USERNAME=xxxxxxxxxxx
heroku config:add SENDGRID_PASSWORD=xxxxxxxxxxxxxxx
If you just want to see what ror_ecommerce looks like, before you enter any products into the database, run the following command:
rake db:seed_fake
If you have not already done so point your browser to http://lvh.me:3000/admin/overviews and set up the admin user.
You should now have a minimal dataset, and be able to see a demo of the various parts of the app. Note: make sure you have config/settings.yml
set up correctly before you try to checkout. Also, please take a look at The 15 minute e-commerce video.
If installing rMagick on OS X 10.8 and using Homebrew to install ImageMagick, you will need to symlink across some files or rMagick will not be able to build.
Do the following in the case of a Homebrew installed ImageMagick(and homebrew had issues):
* cd /usr/local/Cellar/imagemagick/6.8.9-8/lib
* ln -s libMagick++-6.Q16.5.dylib libMagick++.dylib
* ln -s libMagickCore-6.Q16.2.dylib libMagickCore.dylib
* ln -s libMagickWand-6.Q16.2.dylib libMagickWand.dylib
* you may need to change the version path if the imagemagick has been updated
If you would like to read the docs, you can generate them with the following command:
yardoc --no-private --protected app/models/*.rb
First, create config/settings.yml
and change the encryption key and paypal/auth.net information. You can also change config/settings.yml.example
to config/settings.yml
until you get your real info.
To change from authlogic to any other gateway look at the documentation HERE
Paperclip will throw errors if not configured correctly. You will need to find out where Imagemagick is installed. Type: which identify
in the terminal and set
Paperclip.options[:command_path]
equal to that path in config/initializers/paperclip.rb
.
Example:
Change:
Paperclip.options[:command_path] = "/usr/local/bin"
Into:
Paperclip.options[:command_path] = "/usr/bin"
While optional, for a speedy site, using memcached is a good idea.
Install memcached. If you're on a Mac, the easiest way to install Memcached is to use homebrew:
brew install memcached
memcached -vv
Remove the cookie store on line one of config/initializers/session_store.rb
. In your Gemfile add:
gem 'dalli'
then:
bundle install
Finally uncomment the next two lines in config/initializers/session_store.rb
require 'action_dispatch/middleware/session/dalli_store'
Hadean::Application.config.session_store :dalli_store, :key => '_hadean_session_ugrdr6765745ce4vy'
It is also recommended to change the cache store in config/environments/*.rb
config.cache_store = :dalli_store
brew install solr
Uncomment the following in your gemfile:
#gem 'sunspot_solr'
#gem 'sunspot_rails'
then:
bundle install
Start Solr before starting your server:
rake sunspot:solr:start
Go to product.rb
and uncomment:
#include ProductSolr
Also remove the method:
def self.standard_search
Take a look at setting up Solr - Solr in 5 minutes
If you get the error, Errno::ECONNREFUSED (Connection refused - connect(2)):
when you try to create a product or upload an image, you have not started Solr search. You need to run rake sunspot:solr:start
, or remove Solr completely.
Remember to run rake sunspot:reindex
before doing your search if you already have data in the DB
Putting assets on S3 can cause issues with FireFox/IE. You can read about the issue if you search for "S3 & CORS". Basically FF & IE are keeping things more secure but in the process you are required to do some setup.
I ran into the same thing with assets not being public for IE and FireFox but Chrome seemed to work fine. There is a work around for this though. There is something called a CORS Config that opens up your assets to whatever domains you specify.
Here's how to open up your assets to your website. (Thanks @DTwigs)
Now paste this code in there:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Typically a product has many variants. (Variant ~= specific size of a given shoe)
If you have many variants with the same image don't bother with an image group, just use the "products.images".
Use ImageGroups for something like shoes. Lets say you have 3 colors, and each color has 10 sizes. You would create 3 images groups (one for each color). The image for each size would be the same and hence each variant would be associated to the same image_group for a given color.
RoR Ecommerce was created by David Henner. Contributors.
Shipping categories are categories based off price:
you might have two shipping categories (light items) & (heavy items) where heavy items are charged per item purchased and light items are charged once for all items purchased. (hence buying 30 feathers has the same shipping charges as one feather)
Have fun!!!
Author: drhenner
Source code: https://github.com/drhenner/ror_ecommerce
License: MIT license
1622462142
Ruby on Rails is a development tool that offers Web & Mobile App Developers a structure for all the codes they write resulting in time-saving with all the common repetitive tasks during the development stage.
Want to build a Website or Mobile App with Ruby on Rails Framework
Connect with WebClues Infotech, the top Web & Mobile App development company that has served more than 600 clients worldwide. After serving them with our services WebClues Infotech is ready to serve you in fulfilling your Web & Mobile App Development Requirements.
Want to know more about development on the Ruby on Rails framework?
Visit: https://www.webcluesinfotech.com/ruby-on-rails-development/
Share your requirements https://www.webcluesinfotech.com/contact-us/
View Portfolio https://www.webcluesinfotech.com/portfolio/
#ruby on rails development services #ruby on rails development #ruby on rails web development company #ruby on rails development company #hire ruby on rails developer #hire ruby on rails developers