Posts

Address already in use - bind(2) for 127.0.0.1:3000

you need use kill -9 4343 (use lsof -wni tcp:3000 to see which process used 3000 port and get the process pid)

Find places close by a route using Google Maps API V3 and RouteBoxer

<div id="google_map" class="google_map" style="width: 750px; height: 500px;"></div> <script src="//maps.googleapis.com/maps/api/js?v=3.2&amp;sensor=false"></script> <script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/routeboxer/src/RouteBoxer.js"></script> <script type="text/javascript">   //placing a marker on the map function createMarker(map, coords, title) {  var marker = new google.maps.Marker({   position: coords,   map: map,   title: title,   draggable: false  });  return marker; } //Search places having coordinates inside the boxes function findPlaces(boxes) {  var data = "";  for (var i = 0; i < boxes.length; i++) {   //form the query string that will be sent via ajax   if (data != "") {    data += "&";   }   data += "boxes[]=" + boxes[i].getNorthEast().lat() + ":" + boxes[i].getNorthEast().l

disable inherited_resources in ruby on rails

Solution 1 config . app_generators . scaffold_controller = :scaffold_controller Solution 2 config . generators do | g | g . scaffold_controller "scaffold_controller" end Solution 3 To force rails to use the normal scaffold generator, add -c=scaffold_generator to the end of the command

Could not find generator 'refinery:engine'

First run "gem install refinerycms" Then add the following gem then problem will be resolve gem 'refinerycms',      '~> 3.0.0.dev', git: 'https://github.com/refinery/refinerycms.git' gem 'refinerycms-i18n', '~> 3.0.0.dev', git: 'https://github.com/refinery/refinerycms-i18n.git' Then run rails generate refinery:cms --fresh-installation

create our own gem in ruby on rails

$ gem install bundler     $ bundle gem dogeify   This will create following directories   $ tree dogeify dogeify ├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── dogeify.gemspec └── lib    ├── dogeify    │   └── version.rb    └── dogeify.rb         Let's first look at the gemspec file ( dogeify.gemspec in this case).    # coding: utf-8 lib = File .expand_path( '../lib' , __FILE_ _ ) $LOAD_PATH .unshift(lib) unless $LOAD_PATH . include ?(lib) require 'dogeify/version' Gem::Specification .new do |spec| spec.name = "dogeify" spec.version = Dogeify::VERSION spec.authors = [ "Matt Huggins" ] spec.email = [ "matt.huggins@gmail.com" ] spec.description = %q{Convert everyday boring English into doge speak!} spec.summary = %q{English to doge translations} spec.homepage = "" spec.license = "MIT" spec.files

List all countries with code

[       {:name => 'Ã…land Islands', :iso_code => 'AX'},       {:name => 'Albania', :iso_code => 'AL'},       {:name => 'Algeria', :iso_code => 'DZ'},       {:name => 'American Samoa', :iso_code => 'AS'},       {:name => 'Andorra', :iso_code => 'AD'},       {:name => 'Angola', :iso_code => 'AO'},       {:name => 'Anguilla', :iso_code => 'AI'},       {:name => 'Antarctica', :iso_code => 'AQ'},       {:name => 'Antigua and Barbuda', :iso_code => 'AG'},       {:name => 'Argentina', :iso_code => 'AR'},       {:name => 'Armenia', :iso_code => 'AM'},       {:name => 'Aruba', :iso_code => 'AW'},       {:name => 'Australia', :iso_code => 'AU'},       {:name => 'Austria', :iso_code => 'AT'},  

encode and decode image in Base64 in rails

require "base64" encoded_string = Base64.encode64(open("https://s3.amazonaws.com/cdn. yourwellnessroom.com/i/pillarimages/eat/E22.jpg") { |io| io.read }) decode_img= Base64.decode64(encoded_string)   File.open('image.png', 'wb') { |f| f.write(decode_img) }   user.image = image.png'   user.save

Facebook authentication with devise in ruby on rails

Image
Step 1: Preparing your Application    rails new omniauth-tutorial  And integrate devise Step 2: Creating a Provider  In order to add a provider to Omniauth, you will need to sign up as a developer on the provider’s site. Once you’ve signed up, you’ll be given two strings (sort of like a username and a password), that needs to be passed on to Omniauth. If you’re using an OpenID provider, then all you need is the OpenID URL. If you want to use Facebook authentication, head over to developers.facebook.com/apps and click on “Create New App”. Fill in all necessary information, and once finished, copy your App’s ID and Secret. Configuring Twitter is a bit more complicated on a development machine, since they don’t allow you to use “localhost” as a domain for callbacks. Configuring your development environment for this kind of thing is outside of the scope of this tutorial, however, I recommend you use Pow if you’re on a Mac. Add to your  Gemfile : gem ' o

sidekiq css not working in production mode in ruby on rails

Put this in config.ru :-  require 'sidekiq/web' run Rack::URLMap.new(     "/" => Rails.application,     "/sidekiq" => Sidekiq::Web )

List online users with devise in rails

I just add a last_sign_out_at column to my Users table and then subclassed the Devise sessions controller so I could override the destroy method to set it when the session is destroyed (user signs out): # app/controllers class SessionsController < Devise :: SessionsController def destroy current_user . update_attribute (: last_sign_out_at , Time . now ) super end end     And then in my User model I have a method to check if the user is online:   class User < ActiveRecord :: Base def online ? if current_sign_in_at . present ? last_sign_out_at . present ? ? current_sign_in_at > last_sign_out_at : true else false end end end   Also you need to tell Devise to use the new Sessions controller in your routes.  

redirect on multiple sub domain with apache server

 RewriteEngine On RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R]

Whenever cron jobs not working

I added this path in the beginning of schedule.rb:- env :PATH, '/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games'

Add flash message in rails

In app/helpers/application_helper.rb :- module ApplicationHelper     def flash_class(level)         case level         when 'notice' then "alert alert-info"         when 'success' then "alert alert-success"         when 'error' then "alert alert-error"         when 'alert' then "alert alert-error"         end       end end   Somewhere in app/views/layouts/application.html.erb : <%= render 'layouts/flash_messages' %>   app/views/layouts/_flash_messages.html.erb < div > <% flash . each do | key , value | %> < div class = "<%= flash_class(key) %> fade in" > < a href = "#" data - dismiss = "alert" class = "close" >×</ a > <%= value %> </ div > <% end %> </ div > <style> .alert { padding: 8px 35px 8px 14px; margin-bottom: 18px; color: #c09853

Devise login mobile api in ruby on rails

In routes.rb namespace :api do namespace :v1 do devise_scope :user do post "/sign_in" , :to => 'session#create' delete "/sign_out" , :to => 'session#destroy' end end   In  Api::V1::SessionsController:- class Api::V1::SessionsController < Api::V1::ApiController     before_filter :authenticate_user!, :except => [:create]     skip_before_filter  :verify_authenticity_token     respond_to :json         def create            email = params[:email]         password = params[:password]         if request.format != :json           render :status=>406, :json=>{:message=>"The request must be json"}           return         end         if email.nil? and password.nil?           render :status=>400,           :json=>{:message=>"The request must contain the user email and password."}           return         end         @user=User.find_by_email(e

Mobile Rails API with Devise

For the past two weeks I have been working on building out an API for one of our existing Rails apps for use by mobile devices. I started with Android since there were less barriers to entry there (no specialty development hardware needed) as well as perceiving that Java might be more beneficial for my career in the long-run than the Apple-centric Objective-C language. It took me quite awhile to wrap my head around what exactly I needed to accomplish to get this happen at the beginning; many of the tutorials and how-to's out there are outdated and not quite what I wanted, but I think I figured out an effective, secure and easy way to help get you started should you need to accomplish something similar. Before I do anything with the mobile device, we need to build out an API that can be communicated with on the server side of things. In rails, this is remarkably easy. My goal was to allow a user to login remotely, then be able to send either email or text messages t

install wkhtmltopdf in ubuntu

First, installing dependencies:-  sudo aptitude install openssl build-essential xorg libssl-dev For 64-bit OS: wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.2-static-amd64.tar.bz2 tar xvjf wkhtmltopdf-0.9.2-static-amd64.tar.bz2 chown root:root wkhtmltopdf-amd64 mv wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf

run multiple application on apache2

 Open .conf file sudo nano /etc/apache2/sites-available/testapp.conf Put below content in this file:- Listen 88 <VirtualHost *:80>         # The ServerName directive sets the request scheme, hostname and port that         # the server uses to identify itself. This is used when creating         # redirection URLs. In the context of virtual hosts, the ServerName         # specifies what hostname must appear in the request's Host: header to         # match this virtual host. For the default virtual host (this file) this         # value is not decisive as it is used as a last resort host regardless.         # However, you must set it for any further virtual host explicitly.         ServerName 52.5.211.191         ServerAdmin webmaster@localhost         DocumentRoot /home/ubuntu/ywroom-staging/public         RailsEnv production         # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,         # error, crit, alert, emerg.         # It i

How To Deploy a Rails App with Passenger and Apache on Ubuntu 14.04

Image
Introduction In this tutorial, we will demonstrate how to install Phusion Passenger as your Rails-friendly web server, which is easy to install, configure, and maintain. We will integrate it into Apache on Ubuntu 14.04. By the end of this tutorial, we will have a test Rails application deployed on our Droplet. If you prefer Nginx over Apache, take a look at how to deploy a Rails app with Passenger and Nginx on Ubuntu 14.04 by following the link. Prerequisites The first step is to create a new Droplet. For smaller sites it is enough to use the 512 MB plan. You may want to choose the 32-bit Ubuntu image because of smaller memory consumption (64-bit programs use about 50% more memory then their 32-bit counterparts). However, if you need a bigger machine, or there is a chance that you will upgrade to more than 4 GB of RAM, you should consider the 64-bit version. Be sure to use Ubuntu 14.04. At the time of this writing, Ubuntu 14.10 does not have a Passanger

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

If you are trying to connect mysql using password or without password like mysql -u USERNAME or mysql -u USERNAME -p PASSWORD and getting error:-   Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) find first socket location sudo find / -type s my be location would be /tmp/mysql.sock just go in the mysql file my.cnf sudo nano  /etc/mysql/my.cnf and do changes in scocket port            = 3306 socket          = /tmp/mysql.sock [mysqld_safe] socket          = /tmp/mysql.sock nice            = 0 Restart mysql, sudo /etc/init.d/mysql restart And try login again mysql -u USERNAME Hope it will work. Command to know all the mysql variable sudo mysqladmin variables To know mysql socket path mysqld --verbose --help | grep ^socket

run bundle and migration in Automatic deploy with Git

sudo nano hooks/post-receive #!/bin/bash while read oldrev newrev ref do     if [[ $ref =~ .*/master$ ]];     then         echo "Master ref received.  Deploying master branch to production..."         git --work-tree=/home/ec2-user/ywrstaging/ywroom-staging --git-dir=/home/ec2-user/proj checkout -f       # sudo  /etc/init.d/nginx restart        cd /home/ec2-user/ywrstaging/ywroom-staging &&  source ~/.rvm/scripts/rvm && bundle install && rake db:migrate        sudo  /etc/init.d/nginx restart     else         echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."     fi done