Wednesday, 24 August 2016

DropZone Help:
Step-1.
<form action="/projects/<%=current_project.try(:id)%>/uploads/dropzone_file_upload?recommendation_id=<%=recommendation.id%>" class="dropzone" id="demo-upload-<%=recommendation.id%>">
  <div class="dz-message needsclick">
    Drop files here or click to upload.<br />
  </div>
</form>            
<div id="preview-template" style="display: none;">
  <div class="dz-preview dz-file-preview">
    <div class="dz-image"><img data-dz-thumbnail /></div>
    <div class="dz-details">
      <div class="dz-size"><span data-dz-size></span></div>
      <div class="dz-filename"><span data-dz-name></span></div>              
    </div>
    <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
    <div class="dz-error-message"><span data-dz-errormessage></span></div>
  </div>
</div>
<script>
  dropzonSet("<%=recommendation.id%>");
</script>



Step-2.
var dropzonSet = function(recommendation_id){
  docsDropzone = new Dropzone( "#demo-upload-"+recommendation_id, {
  init: function() {
      this.on("complete", function (file) {
        data = JSON.parse(file.xhr.response)
        files=data.attachments>1 ? "Files" : "File"
        $("#attached_file_"+data.recommendation).html(data.attachments + " "+ files +" attached")
        html_remove_image =  "<a href='#' data-href='/uploads/dropzone_file_destroy?upload_id="+data.file+"&recommendation_id="+data.recommendation+"' class='remove-image remove-link-image' data-id='"+data.file+"'>X</a>"
        $(file.previewElement).prepend(html_remove_image)
        total_attachments = $($(".remove-image.remove-link-image").map(function(){return $(this).data("id")}).get()).size()
        file_count = total_attachments > 1 ? "Files" : "File"
        $("#img-attached_file").html(total_attachments + " " + file_count + " Attached");
      });
    }
  } );
}


Step-3.
respond_to do |format|
      format.json do
        render :json => {file: @file.id, recommendation: @recommendation.try(:id), attachments: @recommendation.try(:uploads).try(:size)}
      end
    end

Friday, 5 August 2016

Cap development/production deploy: 

error: RAILS_ENV="production" rake assets:precompile 
Killed

The error is coming because of out of RAM memory, so need to do swap the memory-

follow these command for memory swapping -
sudo swapon -s
Check how much disk space now you have:
 df
create a swap file:
1. Allocate a file for swap
sudo fallocate -l 2048m /mnt/swap_file.swap
2: Change permission
sudo chmod 600 /mnt/swap_file.swap
3: Format the file for swapping device
sudo mkswap /mnt/swap_file.swap
4: Enable the swap
sudo swapon /mnt/swap_file.swap
5: Make sure the swap is mounted when you Reboot. First, open fstab
sudo nano /etc/fstab
and
# /etc/fstab
/mnt/swap_file.swap none swap sw 0 0 
Save it. 
run cap production deploy 
or 
runrake assets:precompile on server 

Cheers,
Hemant

Tuesday, 2 August 2016

Capistrano Deployment error fixed while deployment on Digital Ocean :

gem 'capistrano', '~> 3.4.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1.1'

config/deploy.rb : lock '3.4.1'

cap production deploy

error: 
cd /home/ubuntu/Trusttd/releases/20160802102011 && /usr/local/rvm/bin/rvm default do bundle install --path /home/ubuntu/Trusttd/shared/bundle --without development test --deployment --quiet
/usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:149:in ``': Cannot allocate memory - git (Errno::ENOMEM)
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:149:in `block in git'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/shared_helpers.rb:72:in `call'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/shared_helpers.rb:72:in `with_clean_git_env'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:149:in `git'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:83:in `version'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/env.rb:78:in `git_version'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/env.rb:22:in `report'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:40:in `log_error'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:100:in `rescue in with_friendly_errors'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/bundle:23:in `load'
from /usr/local/rvm/gems/ruby-2.2.3/bin/bundle:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as root@128.199.198.27: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:149:in ``': Cannot allocate memory - git (Errno::ENOMEM)
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:149:in `block in git'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/shared_helpers.rb:72:in `call'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/shared_helpers.rb:72:in `with_clean_git_env'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:149:in `git'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/source/git/git_proxy.rb:83:in `version'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/env.rb:78:in `git_version'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/env.rb:22:in `report'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:40:in `log_error'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:100:in `rescue in with_friendly_errors'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
from /usr/local/rvm/gems/ruby-2.2.3/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/bundle:23:in `load'
from /usr/local/rvm/gems/ruby-2.2.3/bin/bundle:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'




Assign permission for your releases folder after ssh login

sudo chmod -R 777 /home/ubuntu/******/releases/
root@*****:~# cd /home/ubuntu/******/current/
gem install sqlite3 -v '1.3.10
gem install nokogiri 
gem install ransack

then again try
cap production deploy


Cheers,
Hemant