Posts

Changing devise routes like '/users/sign_in' to '/sign_in'

In many of the applications built with the help of Devise sometimes you need to change the devise routes like '/users/sign_in' to simply '/sign_in' 1.)config/routes.rb devise_for :users, :controllers => {registrations: 'registrations'}, :skip => [:sessions]   devise_scope :user do     get "/sign_up" => "devise/registrations#new", :as => :new_one_user_registration     get '/sign_in' => "devise/sessions#new", :as => :new_user_session     get '/forgot_password' => "devise/passwords#new", :as => :new_password     get '/confirmation' => "devise/confirmations#new", :as => :new_confirmation     post '/sign_in' => 'devise/sessions#create', :as => :user_session     delete '/sign_out' => 'devise/sessions#destroy', :as => :destroy_user_session     authenticated :user do       root 'projects#index...

Net::ReadTimeout: Net::ReadTimeout issue in sending mails

Net::ReadTimeout: Net::ReadTimeout issue comes when you are trying to outbound a mail. To solve the issue you need to add a key value pair of tls in your mailer configuration in any environment for ex: 1.)development.rb config.action_mailer.smtp_settings = { :user_name => 'user@domain.com' , :password => 'password' , :address => 'user191@gmail.com' , :domain => 'domain.com' , :port => 465 , :authentication => :login , :enable_starttls_auto => true , :tls => true } 2.)UserMailer.rb default from : "user@domain.com"  

Connecting and Associating multiple databases and their tables in rails(Part 1)

Image
There are several steps that needs to follow to connect with multiple database and create association between two different tables of two different databases First you need to modify your database.yml 1.)database.yml: main_development:    # development configuration goes here secondary_development:    # development configuration to external database goes here # same for test and production... 2.)Models: If you have two different databases the you would have multiple tables in each database and off-Course multiple models in each db now the question is how to establish the connection between two models of two different database . But Rails provide it in easy way #Model in main_database To manually connect each model of main_database with secondary database you need to establish a connection to that database like: class Astronaut < ActiveRecord::Base    establish_connection "nasa_#{Rails.env}" end ...

The server quit without updating PID file in mysql

This is a common issue with mysql faced by many of the user. The solution is related only with permission of user to solve this issue write command    sudo chown -R _mysql:_mysql /usr/local/var/mysql This command will change the ownership of user and -R option does it recursively within a folder mysql to all sub-folders and files.  

Exporting Data to Excel file in Rails

There are two ways of doing the same thing first is to use the gem to_xls-rails and another is without gem I am gonna explain both approaches: Approach 1 :  Using gem  'to_xls-rails' 1. ) bundle install 2.)Your Controller def index @posts = Post.all respond_to do |format| format.html # don't forget if you pass html format.xls { send_data(@posts.to_xls) } end end 3.)Your View <%= link_to 'Excel Download', posts_path(:format => :xls) %> 4.)config/initializers/mime_type.rb Mime::Type.register "application/vnd.ms-excel", :xls   Another way or standard way without any gem

Integration of Facebook API in Rails Application

To Integrate Facebook API into Rails with yml file  1.)Sign in to your fb account 2.)Type developer.facebook.com in url . 3.)Go to App->Register as a developer. 4.) Now again go to app->add a new app->select which platform are you working on for ex:(website)->enter the name of your app->choose a category->create App id. 5.)After this you will get this 'Setup the Facebook SDK for JavaScript' copy the code to notepad for now. 6.)enter the website url you do have if you don't have any url type example.com 7.)After this you will see four options share login social plugins add 8.)Click any of the option which you want in your app for ex: you clicked on Share. 9.)Then read it for your better understanding to the API. 10.)Now again go to your app from app->your app name 11.)enter the display name anything which you like  12.)enter the mail id of yours for contact 13.)Now copy the app id and secret key and t...

Completely Install and Uninstall mysql on mac

To uninstall MySQL and completely remove it (including all databases) from your Mac do the following: Open a terminal window Use mysqldump to backup your databases to text files! Stop the database server sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf /Library/StartupItems/MySQLCOM sudo rm -rf /Library/PreferencePanes/My* edit /etc/hostconfig and remove the line MYSQLCOM=-YES- rm -rf ~/Library/PreferencePanes/My* sudo rm -rf /Library/Receipts/mysql* sudo rm -rf /Library/Receipts/MySQL* sudo rm -rf /private/var/db/receipts/*mysql* To install mysql on your mac do the follwo wing things: brew doctor brew install mysql unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp mysql.server start / usr / local / Cellar / mysql / 5.5.10 / bin / mysql_secure_installation mysql -h localhost -u root mysql>CREATE DATAB...