Skip to main content

Posts

Showing posts from April, 2018

How to manage postgres through command line in Ubuntu?

Step 1: First install postgres in Ubuntu system using following commands. $ sudo apt-get update $ sudo apt-get install postgresql postgresql-contrib libpq-dev To check psql (postgres) version. $  psql –version Step 2:  Now to create root user and password for psql. $  sudo -u postgres createuser -s root $  sudo -i -u  postgres Now, you are in postgres environment. postgres@admin:~$ Now, use the following command to enter and manage psql. postgres@admin:~$  psql Now, set the password for psql username “ root ”. postgres=# \password root enter password confirm Now, you can exit from psql using following command postgres=# \q Step 3:  Create new user and database in psql $ sudo su postgres $ psql -c "create user mack with password 'mack'" $ psql -c "create database mackdb owner mack" $ sudo -i -u postgres postgres@admin:~$  psql Step 4:  Give all privileges over database to a particular user. postgres=# grant all privileges on d

Best In Place Gem In Ruby On Rails Tutorial

The best_in_place gem is the easiest solution for in place editing in Ruby on Rails. This gem provides functionality of “in place editing” in ruby on rails without writing any extra ajax code. It supports text inputs, textarea, select dropdown, checkboxes, jQuery UI Datepickers, etc. Also Displays server-side validation Installation Steps of “best_in_place” Gem : Installing best_in_place is very easy and straight-forward. Just begin including the gem in your Gemfile: gem ‘best_in_place’ After that, specify the use of the jquery and best in place javascripts in your application.js, and optionally specify jquery-ui if you want to use jQuery UI datepickers: //= require jquery //= require best_in_place //= require jquery-ui //= require best_in_place.jquery-ui Then, just add a binding to prepare all best in place fields when the document is ready: $(document).ready(function() { /* Activating Best In Place */ jQuery(".best_in_place").best_in_place(); });

Django

What is Django: Django not only used for making websites, rather than it is used for creating web applications. Django can be used to create dynamic high-security web applications. Django is an open source web application framework, written in Python. A web framework that is a set of components that helps to develop websites faster and easier. For authentication, one of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface. Django Design Principles: Less Coding − Less code so in turn a quick development. Don’t Repeat Yourself (DRY) − everything should be developed only in exactly one place instead of repeating it again and again. Fast Development − Django’s philosophy is to do all it can to facilitate hyper-fast development. Clean Design − Django strictly maintains a clean design principle. throughout its own code and makes it easy to follow best web-development practice

Sending Emails in Rails Applications

Action Mailer is the Rails component that enables applications to send and receive emails. In Rails, emails are used by creating mailers that inherit from “ActionMailer::Base” in app/mailers. Those mailers have associated views that appear alongside controller views in app/views. Now we will build a rails application which will send an email to the user when a new user is created. Let’s create a new rails application. $ rails new sample_app $ cd sample_app $ rails generate scaffold user first_name:string last_name:string phone_number:string email:string $ rake db:migrate Action Mailer- Configuration: Following are the steps you have to follow to complete your configuration before proceeding with the actual work. We will just add following lines of code in  config/environments/development.rb config.action_mailer.delivery_method = :smtp #It tells ActionMailer that you want to use the SMTP server. Generate a Mailer : We now have a basic application, let’s make use

Using JWT in Rails

JWT is a Json Web Token,It is a standard and has been implemented in almost all popular programming languages. Hence, they can be easily used or exchanged in systems implemented in diverse platforms. JWT has libraries for almost all platforms and Ruby is no exception. Now we will see how JWT is used in Rails: We will create a simple Rails application which uses the excellent Devise gem for authentication and the jwt gem for creating and verifying JWT tokens. Let’s create a sample Rails application : rails new rails_on_jwt Once the application is generated, create a Home controller which we will use to check our authentication. Create  home_controller.rb in the app/controllers classHomeController ApplicationController def index end end Write the route for  HomeController to /home in config/routes.rb: Rails.application.routes.draw do get 'home' => 'home#index' end Now, add Devise to our application. First, we will add the Devise and jwt gems