Posts

Showing posts from May, 2015

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

How To Use Git Hooks To Automate Development and Deployment Tasks

Image
Introduction Version control has become a central requirement for modern software development. It allows projects to safely track changes and enable reversions, integrity checking, and collaboration among other benefits. The git version control system, in particular, has seen wide adoption in recent years due to its decentralized architecture and the speed at which it can make and transfer changes between parties. While the git suite of tools offers many well-implemented features, one of the most useful characteristics is its flexibility. Through the use of a "hooks" system, git allows developers and administrators to extend functionality by specifying scripts that git will call based on different events and actions. In this guide, we will explore the idea of git hooks and demonstrate how to implement code that can assist you in automating tasks in your own unique environment. We will be using an Ubuntu 14.04 server in this guide, but any system that c

Increase size of Amazone ec2 instance

Image
Step by Step This article demonstrates how one of our users increased a root EBS volume from 8GB to 30GB. In order to accomplish this, we will show you how once you launch a Linux-based EC2 instance, you can increase the size of your EBS volume using snapshots. All you need to do is launch an instance, create a snapshot from the volume that is attached to the launched instance, then create a new, bigger volume.   Below is a step by step guide that will clarify how to perform this task: First, you need to successfully launch an EC2 instance with EBS as its root device. The root EBS volume is used as a reference, so you can follow the same step for all of the volumes. Next, connect the instance via PuTTY (in Windows machines) or an SSH client (in Linux machines). We are using PuTTY for our exercise. Run the command “df –h”. It will display the drive’s details before resizing. To increase the size of the root volume, since this is an EBS-backed instance, first stop the

nginx: unrecognized service

The nginx: unrecognized service error means the startup scripts need to be created. Fortunately the startup scripts have already been written. We can fetch them with wget and set them up following these steps: # Download nginx startup script wget -O init-deb.sh https://www.linode.com/docs/assets/660-init-deb.sh # Move the script to the init.d directory & make executable sudo mv init-deb.sh /etc/init.d/nginx sudo chmod +x /etc/init.d/nginx # Add nginx to the system startup sudo /usr/sbin/update-rc.d -f nginx defaults Now we can control nginx using: sudo service nginx stop sudo service nginx start sudo service nginx restart sudo service nginx reload

MySQL: Grant all privileges on database

GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%' WITH GRANT OPTION; OR This is old question but I don't think the accepted answer is safe. It's good for creating a super user but not good if you want to grant privileges on a single database. grant all privileges on mydb.* to myuser@'%' identified by 'mypasswd'; grant all privileges on mydb.* to myuser@localhost identified by 'mypasswd';

callback methos rspecs in ruby on rails

Add gem 'shoulda-callback-matchers' In app/models/user.rb class User < ActiveRecord::Base   after_create :create_usersetting   before_destroy :delete_user_information end In spec/models/user_spec.rb  require "rails_helper"  require 'factory_girl_rails' describe User do   before(:each) do     @user = User.create(:email=>"example@gmail.com",:password=>"1234578")   end it "should trigger create_usersetting on after create" do      should callback(:create_usersetting).after(:create)        end        it  "should trigger delete_user_information on before destroy" do       is_expected.to callback(:delete_user_information).before(:destroy)     end end