Posts

Showing posts from 2017

DEPLOYING PROJECT USING CAPISTRANO (CAPISTRANO IN RAILS)

Image
We can Deploy project on Digital Ocean, AWS, Transip, Linode server ... using CapistranoWhat is Capistrano:- Capistrano is a remote server automation tool.

It supports the scripting and execution of arbitrary tasks, and includes a set of sane-default deployment workflows.

For that we have to follow simple steps :- How to Install Capistrano We can use Capistrano in RAILS 4, RAILS 5 as well as RAILS 2 and 3 . If we use RAILS 4 and 5 , then we can follow these steps :- 1.  Gemfile:- group :development do
             gem "capistrano"
             gem 'net-ssh'
             gem 'capistrano-bundler'
             gem 'capistrano-rails'
             gem 'capistrano-rvm'
             gem 'capistrano-sidekiq'
       end


2.   Run the bundle      cd /path/to/your/projectbundle 3.   Prepare your Project for Capistrano       capify .       This will create:       Capfile in the root directory of your Rails app       deploy.rb file in the config directo…

*** No MethodError Exception: undefined method 'split' for : "content-type": Symbol

When we upload the videos using carrier wave or paperclip then we mostly getting some content-type error like -*** No MethodError Exception: undefined method 'split' for : "content-type": Symbol
Then we have to check our RVM Version if version is  ruby-2.2.1

WE NEED TO CHANGE OUR RVM:-
WE NEED TO USE :-


 ruby-2.3.1

CARRIERWAVE - UPLOAD ANY MEDIA (AUDIO , VIDEO AND IMAGE ) FILE IN RAILS

Image
UPLOADING ANY MEDIA FILE WITH CARRIER-WAVE RAILS Multiple file uploads Add it to your Gemfile:      gem 'mime-types'
      gem 'mini_magick'
      gem 'rmagick'
      gem 'carrierwave', '~> 1.0'
      gem 'carrierwave-video'
      gem 'carrierwave-video-thumbnailer'
      gem 'carrierwave-ffmpeg'
Run
      bundle

Start off by generating an uploader:app/uploaders/vimeo_uploader.rb      rails generate uploader Vimeo Check out this file for some hints on how you can customize your uploader. It should look something like this:class VimeoUploader < CarrierWave::Uploader::Base
storage :file
end
If we want to upload video or image then we will have to use :-class VimeoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
      include CarrierWave::Video
      include CarrierWave::Video::Thumbnailer
      include CarrierWave::FFmpeg

      storage :file
     def store_dir
         "uploads/#{model.class.to_s.undersc…

RESTART THE DROPLET OR EC2 INSTANCE FROM COMMAND LINE

RESTART THE DROPLET OR EC2 INSTANCE FROM COMMAND LINE Login to your droplet or virtual console using ssh command :-Run the command :-

sudo shutdown -r now

We can follow the link below :-


https://www.digitalocean.com/community/questions/how-to-reboot-droplet-through-the-command-line-restart-apache-server

https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-console-to-access-your-droplet

SUDO: UNABLE TO RESOLVE HOST WEBSERVERNAME

sudo: unable to resolve host webservername For that:- We have to write the below line in /etc/hosts127.0.1.1 webservername



We can follow the link below :-

https://askubuntu.com/questions/59458/error-message-sudo-unable-to-resolve-host-user

CREATE API FOR USER SIGN UP, LOGIN AND CREATE PUBLISHER WITH CURRENT USER

Image
User Registration in Devise through API I have recently started developing REST APIs with rails 5. I am trying to do User crude actions through API calls. I have set up a basic devise for users.In my routes I have this: namespace :api do                                                                            
     namespace :v1 do                                                                         
         devise_scope :user do                                                               
            post 'signup' => 'registrations#create'                                   
            post 'signin' => 'sessions#create'                                          
            delete 'signout' => 'sessions#destroy'                                    
         end                                                                                          
         resources :publishers������������������������������������������…

COULDN'T CONNECT TO SERVER 127.0.0.1:27017 (START MONGO DB)

COULDN'T CONNECT TO SERVER 127.0.0.1:27017 START MONGO DB SERVER sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongod start

OR WE CAN USE sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath /var/lib/mongodb
sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
sudo service mongodb start


http://stackoverflow.com/questions/12831939/couldnt-connect-to-server-127-0-0-127017
WHEN WE UNABLE TO START MONGO DB THEN WE CAN FOLLOW https://stackoverflow.com/questions/9757925/upgrade-mongodb

ADDING SWAP TO AWS EC2 INSTANCE + MEMORY ALLOCATION PROBLEM

Adding Swap to Aws EC2 instance:-sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1
If you need more than 1024 then change that to something higher. To enable it by default after reboot, add this line to /etc/fstab:swap        /var/swap.1 swap    defaults        0   0 To turn ON the swap do the following:swapon -a To turn off the swap do the following:swapon -a To turn off the swap do the following:sudo /sbin/swapoff /var/swap.1

SIGN UP ON FIRST PROJECT IT WILL AUTOMATICALLY LOGIN TO ANOTHER PROJECT SERVER

Sign up on first project it will automatically sign up to another project server In first server code :-Gemfile
gem 'rest-client'


Controller

def create
# sign up on one server
               @user = User.create(name: params[:user][:name], email: params[:user][:email], password: params[:user][:password], password_confirmation: params[:user][:password_confirmation])

# after login one server it will automatically on second server
               RestClient::Request.execute(method: :post, url: "https://ipaddress/domain/users", headers: {:params => {"user": {"name": "rohit", "email": "rohityuvasoft149@gmail.com", "password": "12345678", "password_confirmation": "12345678"}}}, verify_ssl: false)
    end
       end
In second server it will be sign up automatically.

SELECT COUNTRY WITH STATE AND IT'S CITIES RAILS

Country State Select is a library that provides an easy API to generate Country , State / Province and City dropdowns for use in forms.We will refer :-

https://github.com/arvindvyas/Country-State-Select Gemfilegem 'chosen-rails'
gem 'country_state_select', git: 'git://github.com/arvindvyas/Country-State-Select', branch: :master
gem "simple_form"#, "~> 3.2"
gem "reform"#, "~> 2.0"
gem "reform-rails"
orders_controller.rbclass OrdersController < ApplicationController
    def shipping_address
        @location = Address.new
    end
end
shipping_address.html.erb<%= simple_form_for @location,  :html => {class: 'subscribe-from'} ,url: orders_shipping_address_path do |f| %>
  <div class="row">
    <div class="col-md-6">
      <div class="form-group">
        <%= f.input :address_line1, label: "Country", collection: CountryStateSelect.countries_co…

RUN HTML TEMPLATE IN APACHE2 LOCALHOST

Image
When we want to run the html template or html page like :-

URL:-
     file:///home/rohit/Desktop/index.html

We can also run the application in the localhost:-

URL:-
      localhost/index.html

Install Apache:-

sudo apt-get install apache2then goto the /etc/apache2/sites-available/000-default.confDocumentRoot /home/rohit/Downloads/html_pagesinstead of :-#DocumentRoot /var/www/htmlThen go to the :- /etc/apache2/apache2.conf <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /home/rohit/Downloads/html_pages> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> then run:-In the URL :-localhost/We can also refer :-https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Set_up_a_basic_working_environment