Friday, 20 January 2017

Caching with Rails: An Overview

1) Page Caching  : gem actionpack-page_caching

2) Action cashing : gem actionpack-action_caching

3) Fragment Caching : By default Rails provides

4) Russian Doll caching


Thursday, 19 January 2017

Rails Encrypt and decript a key encoding in rails or decoding in rails ruby on rails encrypt decrypt

 
 Create This model in your Model directory : where ever you want to use just include PublicAccessViewHelper
and call encrypt and decrypt method for encryption code and decrypting secret key
 
 
require 'openssl'require 'base64'require 'addressable/uri'require 'uri'

module PublicAccessViewHelper
    def self.included(base)
      base.extend self    end
    def cipher 
 OpenSSL::Cipher::Cipher.new('aes-256-cbc')  # ('aes-256-cbc')    end
    def cipher_key      '@!\xF\xCD\x\x18d\xFD\xFx91\xD4\x03\x92ym\x8F\xD3\x807\xC3\98\xE0\x8E\x8F\xD5T$T\x1CAF\x1Fc\tZE\xE0\x04\xD5\xD7|(J\x8B\xE14\x03S\xF3\xE2y\\X\x9E'    end
    def decrypt(encrypted_data)
=begin      c = cipher.decrypt      c.key = Digest::SHA256.digest(cipher_key)      URI.encode(c.update(Base64.decode64(value.to_s)) + c.final)
=end      # URI.decode(value)      # salt  = SecureRandom.random_bytes(64)      # key   = ActiveSupport::KeyGenerator.new('password').generate_key(salt) # => "\x89\xE0\x156\xAC..."      crypt = ActiveSupport::MessageEncryptor.new(cipher_key)
      crypt.decrypt_and_verify(encrypted_data)
    end
    def encrypt(secret_data)
      crypt = ActiveSupport::MessageEncryptor.new(cipher_key)
      encrypted_data = crypt.encrypt_and_sign(secret_data)
      return encrypted_data=begin      c = cipher.encrypt      c.key = Digest::SHA256.digest(cipher_key)      URI.encode(Base64.encode64(c.update(value.to_s) + c.final))      URI.encode(value)=end    end
    def encrypt_url(value)
      c = cipher.encrypt
      c.key = Digest::SHA256.digest(cipher_key)
      Base64.encode64(c.update(value.to_s) + c.final)
    end
end

Monday, 2 January 2017

Create Jquery function for check element exist

jQuery.fn.exists = function(){return this.length>0;}


Example :

if($(".spl_req").exists()){   console.log("Element Exist");}else{
 console.log("Element Not Exist");
} 

Friday, 30 December 2016

Select tag in rails form to disply selected value OR accessing Table value in form object

 
= f.select :traveler_id
  ,options_for_select( 
                  @individual_trips.map{|d| [d.individual.full_name,d.individual_id]}
                 ,f.object.traveler_id
                )
 
 
OR
 
 
Accessing Values by form object 
 
 
f.object.id
f.object.name 

Friday, 16 December 2016

Custome Scrollbar in HTML Files mcustomscrollbars

DropZone Js with ajax & Multiple photo and file upload functionality

HTML=======>
 
%form.uploadform.dropzone.no-margin.dz-clickable{:action => ""}
  .dz-default.dz-message    %span Drop your Cover Picture here
  .event_photo_upload_btn#event_photo_upload_btn Upload



JAVASCRIPT====>>
Dropzone.autoDiscover = false; // keep this line if you have multiple dropzones in the same page

$(".uploadform").dropzone({  autoProcessQueue: false, // To stop auto upload  acceptedFiles: "image/jpeg",  url: 'file_photo_upload',  //maxFiles: 1, // Number of files at a time  //maxFilesize: 1, //in MB  maxfilesexceeded: function(file)  {    alert('You have uploaded more than 1 Image. Only the first file will be uploaded!');  },  init: function () {     var submitButton = document.querySelector("#event_photo_upload_btn")         myDropzone = this; // closure
     submitButton.addEventListener("click", function() {         //var status_message = $("#status_txtbox_post").val().trim();         var files = myDropzone.files.length;         console.log("No of files ="+files);         if(files > 0){           myDropzone.processQueue(); // To upload files         }else{              $("#my-dropzone").attr('style','border-color:red !important');         }     });
    this.on("sending", function(file, xhr, data) {      var event_id = $("#event_id").val();
      data.append("attachable_id", event_id);      data.append("event_id", event_id);      data.append("trip_id", trip_id);      data.append("isPhoto", true);      data.append("isDoc", false);      data.append("attachable_type", 'DailyItinerary');    });  },  success: function (response) {    var x = JSON.parse(response.xhr.responseText);    $('.icon').hide(); // Hide Cloud icon    //$('#uploader').modal('hide'); // On successful upload hide the modal window    $('.img').attr('src',x.img); // Set src for the image    $('.thumb').attr('src',x.thumb); // Set src for the thumbnail    $('img').addClass('imgdecoration');    //this.removeAllFiles(); // This removes all files after upload to reset dropzone for next upload    console.log('Image -> '+x.img+', Thumb -> '+x.thumb); // Just to return the JSON to the console.  },  addRemoveLinks: true,  removedfile: function(file) {    var _ref; // Remove file on clicking the 'Remove file' button    return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;  }});