Posts

Showing posts from April, 2017

INSTALLING RADIS AND SIDEKIQ

Install redis on Server:- We can follow :-

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis

       Server start:      sudo service redis_6379 start
       Server stop:     sudo service redis_6379 stop

Install Sidekiq:-

https://github.com/mperham/sidekiq/wiki/Getting-Started

Run Sidekiq:-

bundle exec sidekiq

IMPORTING CSV FILE DATA IN RAILS

We would like to import data from a CSV file into an existing database table. I do not want to save the CSV file, just take the data from it and put it into the existing table.

We need to put the gem in your gemfile:-

gem 'roo'

def import
file = "Desktop/rohit.csv"
# or
          file = "Desktop/rohit.xlsx"    # you can import any csv or xlsx file

          doc = Roo::Excelx.new(file, nil, :ignore)
          header = doc.row(1)          # if we need header
          (2..doc.last_row).each do |i|
              row = Hash[[header, doc.row(i)].transpose]
              puts "#{row["id"]}"
          end
end

MYSQL IMPORT & EXPORT

Import your database using the following commandmysql -u username -p new_database < data-dump.sql Export your database using the following commandmysqldump -u username -p database_name > data-dump.sql

RUN SERVER ON PORT 80 OR LOCALHOST

If we want to Run the server as localhost :-Run the server in local :- 

RAILS_ENV=production rails server --binding=45.55.68.225
IF we want to run the application in port 80 on the server :- Run the server automatically using -d command :-
rails s -b 192.241.185.128 -p 80 -d