Posts

Showing posts from March, 2017

UPLOADING IMAGE ON DROPBOX

Image
Paperclip Dropbox WE CAN USE FOLLOWING LINKS :- https://github.com/thoughtbot/ paperclip https://github.com/janko-m/pap erclip-dropbox PLEASE READ STEPS CAREFULLY.. 1.   Create drop box account. 2. Go to drop box developer console, Create App on drop box. https://www.dropbox.com/develo pers           Now move to the coding part.. 1. Add the gem in gemfile and run bundle.      gem "paperclip-dropbox", ">= 1.1.7"     gem "paperclip", "~> 4.2" 2. Run the following command,     rails g paperclip users avatar    if you getting issue in rails 5 you have to put in the migration :-    class AddAttachmentFileToProfiles < ActiveRecord::Migration[5.1]     end 3. Write this in user model.     class Profile < ApplicationRecord        has_attached_file :file        validates_attachment_content_type :file, :content_type => []     end 4. Add the following line to environme

AUTOCOMPLETE TEXT FIELD IN JAVASCRIPT RAILS

AUTOCOMPLETE TEXT FIELD IN JAVASCRIPT RAILS HTML PAGE <%= text_area_tag :query_editor, '', :onkeyup => "textAreaAdjust(this)", :onclick => "textAreaAdjust(this)", :style => "overflow:hidden" %> <script>    function textAreaAdjust(o) {      o.style.height = "1px";      o.style.height = (1+o.scrollHeight)+"px";    } </script> <style type="text/css">   .add_query_editor {       margin-top: 15px !important;       min-height: 120px;       font-size: 14px !important;       padding-left: 10px !important;       padding-top: 10px !important;       width: 93% !important;       float: left;   } </style> WE CAN FOLLOW :-  http://jsfiddle.net/happysmile s/F33Av/22/ http://jsfiddle.net/aaki/hMJEy /1/ http://jsfiddle.net/2t9Dh/

FOLDER PERMISSION IN RAILS

When we deploy the project on server, Then sometimes the public folder want's the permission. For that we can give the permission from Rails. Creating dir or folder with permission ;- FileUtils.mkdir 'csv_imported', :mode => 0777 Give the permission of created dir or folder :- FileUtils.chmod(0777, "csv_imported") Delete the Directory:- FileUtils.rm_rf('csv_imported' ) Give the permission of particular files :- File.chmod(0777, path) Join the folder with root directory :- csv_folder = Rails.root.join('csv_imported' ) Create random csv files :- csv_name = SecureRandom.urlsafe_base64 + ".csv" Rename the file :- File.rename("rohit.csv", csv_folder + csv_name ) You can also refer :- https://www.ruby-forum.com/top ic/204064

MONGODB IMPORT AND EXPORT DATABASE

Import Mongodb Database:- mongorestore -d newdatabasename dumpfoldername Export(dump) Mongodb Database:- mongodump -d databasename -o /var/deploy

ADD AUTHORIZED KEY ON AWS

Add authorized key on AWS:- cat ~/.ssh/id_rsa.pub | ssh -i /home/Downloads/pemfile.pem username@ec2-**-***-***-***.us-west-2.compute.amazonaws.com 'cat >> ~/.ssh/authorized_keys'

INSTALLING MYSQL ON SERVER DIGITAL OCEAN

Installing mysql on Digital Ocean :- we will refer :- https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04 You can use this :- gem 'mysql' Path :-  /usr/bin/mysql development:   adapter: mysql2   encoding: utf8   reconnect: false   database: data_dev   pool: 5   username: root   password: root   socket: /var/run/mysqld/mysqld.sock production:   adapter: mysql2   encoding: utf8   reconnect: false   database: data_pro   pool: 5   username: root   password: root   socket: /var/run/mysqld/mysqld.sock

MYSQL DATABASE YML FILE

When we create new app or we want to use mysql database then sometimes we forgot the mysql database.yml file setting:- You can use this :- gem 'mysql' database.yml    default: &default       adapter: mysql2       encoding: utf8       pool: 5       username: root       password:       socket: /opt/lampp/var/mysql/mysql.sock   development:       <<: *default       database: database_name   test:       <<: *default       database: database_name   production:       <<: *default       database:  database_name