Skip to main content

Posts

Showing posts from December, 2017

Simple way to document API in Ruby on Rails using swagger document

After creating REST API, it’s important that API should be documented, so the others can use the documentation and understand the requirement and implementation of API. Swagger documentation provides the interface to REST APIs which allows people and system to understand the API without access to source code. Use ‘swagger-docs’ gem to document the API. This will generate swagger-ui json files for rails apps with APIs specification that can be used by person to know about the APIs. To start create swagger_docs.rb file in config/initializers and define your APIs as below: Swagger::Docs::Config.register_apis({ "1.0" => { :api_extension_type =>:json, # path for .json files :api_file_path =>"public", :base_path =>"http://api.somedomain.com", :clean_directory =>false, :attributes => { :info => { "title" =>"Swagger Sample App", } } } }) Swagger document contain the json controller which has

How to implement breadcrumbs functionality in Ruby on Rails app?

Breadcrumbs are graphical control element used as navigational aid in user interfaces. Today I am going to explain how it can be implemented in Ruby on Rails in simple steps as follows: Step 1: Create a sample app using scaffold Step 2: Add"breadcrumbs_on_rails" gem to the Gemfile and install it. Step 3: Create a home.html.erb in articles for home page and route for it. --> app/views/articles/home.html.erb Welcome This is the home page of Sample Article <%= link_to "Articles", articles_path%> --> config/routes.rb root 'articles#home' Step 4: Add breadcrumb for home page. In Articles Controller create method “add_breadcrum” to set the braedcrumb for home path like this: --> app/controllers/articles_controller.rb defadd_breadcrum add_breadcrumb " Home ".html_safe end For every view page set home page as the first breadcrumb in articles controller by the default using: before_action :add_breadcrum

Elasticsearch - Advantages of Distributed Search Data

Elastic-search is a platform for distributed search and analysis of data in real time. Its popularity is due to its ease of use, powerful features, and scalability. Today I am going to brief about the advantages of using elastic-search. It is as follows: Elastic-search What are Elastic-search Advantages Schema Free Full text search Document oriented Rest full API Support Built on top of Lucene Elastic search is very fast DataBase: Mysql, postgress Elastic-search uses JSON objects as responses, which makes it possible to invoke Elastic-search server with a large number of different programming languages Elastic search is developed on Java, which makes it compatible on almost every platform Elastic search is real time, in other words after one second the added document is searchable in this engine Elastic-search supports almost every document type except those that do not support text rendering Elastic-search lets you perform and combine

How to create Drag and Drop functionality in Ruby On Rails?

I have seen many developers that are looking for creating "Drag and Drop" functionality in Ruby On Rails technology. So I'm going to brief about a sample to create and implement this functionality using JQuery Rails, JQuery UI Rails and Rails Sortable gems. Given below are simple steps required to create the rails application: Ruby On Rails Programming How to create Drag and Drop functionality in Ruby on Rails? First of all we will create a simple application first to create the products. The first Step we required to create the Rails Application. $ rails new SampleSortRails By using the scaffold we will generate the the MVC components needed for Simple Products application form $ cd SampleSortRails $ rails g scaffold Product name:string description:text quantity:integer price:integer sort:integer Create the Products database table: $ rake db:create $ rake db:migrate Rails uses rake commands to run migrations. Migrations are Ruby clas

How to Cleanup the Routes in Rails App Using ‘Traceroute’ gem?

Code cleanup refers to the act of writing code so that it cleans up leftover data structures and other unwanted materials from memory and the file system. It is not the same as refactoring code, which involves making the source code itself easier to understand, maintain, and modify. TraceRoute is the tool helpful for code cleanup. Integrate this gem in the Rails application by putting this gem into gem file. Traceroute is a route cleaning tool for Rails applications. It provides a simple rake task for checking which routes are mapped to non existing controller actions, and finds out which controller actions are not reachable. Cleanup the Routes in Rails App Using ‘Traceroute’ gem The following steps with the description implements Traceroute for code cleanup using traceroute gem in our ruby on rails application easily. STEP 1. gem install traceroute STEP 2. Bundle Install STEP 3. Type rake traceroute in command prompt and press Enter. List will appears w