Thursday 10 September 2015

Recapture gem integration steps:


1, add recaptcha gem to gemfile.
gem 'recaptcha', :require => 'recaptcha/rails'
2, the run bundle
bundle install
3, register an app in google recaptcha with following link
https://www.google.com/recaptcha/admin
4, add recaptch.rb with following code in instializers
Recaptcha.configure do |config|
  config.public_key  = 'xxxxxxxxxxxxxxxxxxxc' #site key
  config.private_key = 'xxxxxxxxxxxxxxxy' #secreat key
  config.api_version = 'v2'
end
5, add below tag in sign up form
<%= recaptha_tags %>
6, add below code in regitsration create method
def create
if verify_recaptcha
super
else
build_resource(sign_up_params)
flash.now[:alert] = 'There was an error with the recaptcha code below. Please re-enter the code.'
render :new
end
end

that's it..

Friday 4 September 2015

Validates Email Field From Controller



class User
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

if valid_email?(user.email)
user.save
redirect_to root_url, :notice => 'Good email'
else
flash[:error] = 'Bad email!'
render :new
end

private
def valid_email?(email)
email.present? &&
(email =~ VALID_EMAIL_REGEX) &&
User.find_by(email: email).empty?
end
end

Thursday 3 September 2015

Sublime text2 package control install:



Go to link
https://packagecontrol.io/installation
Copy python code for sublime text2/3

ctrl+`  --> To open console.

Paste python code, then press enter

Restart sublime.

Ex: To install trailing spaces.

Then install package Trailing spaces(like package control)

ctrl+shift+p search for package control press enter.

ctrl+shift+p search for trailing space press enter.