Why Ruby on Rails is Popular among Developers and Entrepreneurs?

Not so long, just ten years ago, the Rails framework was written in Ruby programming language.

According to Hotframework ranking statistics, “Rails reside in the 4th place at the overall catalog of frameworks used now-a-days”.

Ruby on Rails Ranking on HotframeworksSource: Hotframeworks.com

GitHub warehouse, StackOverflow query and questions, and Google Trends all are displaying the same statistics.

Overall Framework Catalog Ranking
Overall Framework RankingSource: Hotframeworks.com

So, the first question arises, why this Ruby on Rails is so popular between both developers and entrepreneurs?

Many merchandise owners think Ruby web development is the most prolific way to build web applications. Well, it’s not an uncovered claim. It permits efficient ways for structuring applications at every step of the development procedure when many significant mechanisms can be generated as an alternative to being coded.

Never miss an update for us. Join 10,000+ marketers and leaders.

Ruby on Rails includes many established techniques and methods, familiar by both beginners and experienced developers, to deliver high-quality software. So, it would be easier to maintain the code in the future even, the addition of new features and making other changes would be like a piece of cake also.

First let’s see, how it works?

Well, Ruby development works for countless projects; however, it is an ideal option if your site or app refers to one of the mentioned classes:

  • E-commerce: Ruby on Rails offers significant forms with very familiar user-friendly feature and modular based approach for most e-commerce sites.
  • Content Management: Ruby web development would be the perfect choice for those websites which exhibit lots of database-friendly content such as the article, audio, video etc. It gives the easiest navigation to the site, upload and manages content as well.
  • Custom Database Solutions: ROR works perfectly at higher database configuration for different business models.
  • Membership Sites: Rails is good for subscription sites, membership site and social networking enabled sites. It has a number of plug-ins, which helps resolve approximately any job of social networking.

Sites like ShopifyHuluGrouponTwitterZenDeskYellowPages, and GitHub has developed with Ruby on Rails.

Here at Andolasoft, we also have vast experience in building projects on Ruby on Rails. Below are only a few examples:

Portfolio for Ruby on Rails Projects

Now come to the main query, Why Ruby on Rails is so popular?

Ruby on Rails’ reputation between developers and business owners has risen rapidly. Let’s find out some reasons.

1. Ruby is an ideal answer for MVP development

Development of Minimum Viable Product (MVP) to authenticate the thought with a user base is the baseline for a startup approach. Startups’ software development procedure is often limited by time and budget. So, it is essential to find the development team who would run programming tools. Below I have tried to explain a few reasons why it is good for building an MVP.

  • Fast programming: The tempo of MVP development in Ruby is much advanced in contrast with that incomparable language such as PHP or Python. When you’re into startup you always need to manufacture products as fast as possible. Ruby with its built-in development tools and handy elements allows you to speed up the development procedure and focus on your core business.
  • Strong Ecosystem and Higher Compatibility. Ruby on Rails having an enormous set of features such as multi-platform compatibility, object-oriented, bunch of free plugins (gems) and best compatibility with other frameworks.
  • Save on development costs: Rails’ machinery significantly clips the financial plan of the project, which is particularly precious for startups. Also, RoR does not involve any costs if you want to re-use, change, duplicate and allocate it.
  • Easy to scale: Startups get hold of a working model inside a short time without spending much funds. This model may develop into a complete application with fewer efforts.

2. Easy API Formation for Mobile Apps

Application developed with Ruby on Rails uses RESTful structural design by default. It allows APIs creation easier and it is a well-recognized model among mobile and web programmers as well. You do not require hiring a new developer to implement RESTful code either.

3. Ruby is perfect for agile projects

RoR’s modular design helps to reproduce the instant changes rapidly with no loss in code and quality. Product proprietor is also able to give immediate feedback, and new versions can be implemented instantly. Automated tests in Rails structure help make sure the lack of bugs throughout code adjustment and it does not require extra documentation.

4. Community support

Community support for Ruby on Rails is just amazing – Ruby developers can get free online tutorials. The Ruby developer community forever keeps the framework advanced.

5. Automation and Development Smoothness

This is part where developers love Ruby on Rails. The framework automates many manual odds so that developers can put their focus on the project’s core features. It makes sure the immense efficiency of development procedure where the product proprietors get impressed.

I’ve worked with the team at AndolaSoft on multiple websites. They are professional, responsive, & easy to work with. I’ve had great experiences & would recommend their services to anyone.

Ruthie Miller, Sr. Mktg. Specialist

Salesforce, Houston, Texas

LEARN MORE

Last but not least, the framework offers economical, quick and dependable testing, which create it a charming spot for developers.

In other hands, outstanding maintain and automated structure of Ruby on Rails are the main reasons why it is so demand able.

Now that you know, what is Ruby on Rails used for and why it is popular for many developers and gainful for an extensive range of entrepreneurs. We could say it is one of our favorite development tools. In the end, Ruby on Rails outsources permits you to get a project within less period of time without giving up quality and performance of your application or website.

Are you planning to build your dream project on Ruby on Rails? Let’s Discuss!

Supercharge your Rails app development with “Metric_fu”

Why we need Metric_fu?

Sometimes we are unaware of unknown complexities in our rails code and it gets messy. Moreover, it reduces application performance, scalability and maintainability.

What is Metric_fu?

Metric_fu is a set of rake tasks and compilation of several different tools that provides reports. This show which parts of your rails code might need extra work. It uses the following built-in tasks to create a series of reports.

  • Rcov – Measures test coverage
  • Flog – Measures code complexity
  • Saikuro – Measures cyclomatic complexity
  • Flay – Finds duplication (both copy/paste and structural)
  • Reek – Spots code smells
  • Roodi – Finds lots of general problems
  • Churn – Identifies files that changes too often
  • Rails best practices – code matric tool
  • Cane -code quality threshold violations
  • HotSpot– Meta analysis of your metrics to find hotspots in the code

Benefits of Metric_fu

  • You can measure the complexity of rails code
  • Creates a “hit list” of most complex methods
  • Reveals hidden issues like bugs and other complexities
  • Examine worst offenders
  • Refactoring complex methods
  • Creates smaller, easier to understand methods

Step#1

  • Add ‘metric_fu’ gem to your gem file
gem "metric_fu"
  • Run “bundle install”

Metric_fu will install several other dependencies unless they are already present.
These include Flay, Flog, Rcov, Reek, Facets and Roodi.

  • Run following command to generate the metrics
rake metrics:all

It will generate a metric of your code in the temp/matric_fu repository,
it uses a number of other open source project to generate the metric.
metrics_home_page-1024x551

Rails_best_pratices_metrics-840x1024

Code analysis isn’t an exact science and none of the tools shown are perfect in themselves.
So they should all be used as an aid to help you find complex areas of your code and supercharge Rails app development.

4 Simple Steps To Implement “Delayed Job” In Rails

Here in this article, I going to tell you the best way to implement “delayed job” in rails

“delayed_job” is a ruby gem used to execute tasks as a background process in Rails environment, increasing page rendering speed.

Delayed::Job (or DJ) allows you to move jobs into the background for asynchronous processing.

Why you need a background process and is it really that important!

Let’s consider a scenario where a mailing application needs to send emails to a huge list of recipients. In such cases it is obvious that the processing time is too long, annoying the users.

Here are some of key points to consider:

  • Incredibly quick & easy to get rolling
  • No addition to your “stack”, runs just fine with Active Record
  • Good choice for beginners while migrating code from foreground to the background

Hence, it’s only wise to move the long running tasks as a background process by using “delayed_job” gem.

Detailed steps to integrate delayed job in a Rails application

Step# 1

  • Add gem to the Gemfile
  • “delayed_job” supports multiple back-ends for storing the job queue
  • To use “delayed_job” with Active Record, use gem ‘delayed_job_active_record’
  • To use “delayed_job” with Mongoid, use gem ‘delayed_job_mongoid’

Example

/Gemfile.rb

  • gem ‘delayed_job_active_record’, ‘4.0.3’
  • Run “bundle install” to install the “delayed_job” gem

Step# 2

  • Generate the related file for the Job run
  • Generate related files required to run the background job by running the following command
    • rails g delayed_job:active_record

It adds following files to the application

  • A Script named “delayed_job” inside “/bin” folder to run the jobs which are in queue.
  • Migration file to create a table to store the job with other information such as priority, attempts, handler, last_error, run_at, locked_at, failed_at, locked_by, queue.

Run the migration file by using the following command

  • rails db:migrate

Set the queue_adapter in config/application.rb

  • config.active_job.queue_adapter = :delayed_job

If you are using the protected_attributes gem, it must appear before delayed_job in your gemfile. If your jobs are failing with:

  • Setup Delayed::Job config in an initializer (config/initializers/delayed_job_config.rb)
    • Delayed::Worker.destroy_failed_jobs = false
    • Delayed::Worker.sleep_delay = 60
    • Delayed::Worker.max_attempts = 3
    • Delayed::Worker.max_run_time = 5.minutes
    • Delayed::Worker.read_ahead = 10
    • Delayed::Worker.default_queue_name = ‘default’
    • Delayed::Worker.delay_jobs = !Rails.env.test?
    • Delayed::Worker.raise_signal_exceptions = :term
    • Delayed::Worker.logger = Logger.new(File.join(Rails.root, ‘log’, ‘delayed_job.log’))

Step# 3

  • Replace script/delayed_job with bin/delayed_job
  • Start up the jobs process

There are two ways to do this.

  • If application is in development mode, we would use the below rake task instead.
    • rake jobs:work
  • If application is in production mode, then it is preferred to use the “delayed_job” script. This demonizes the job process and allows multiple background processes to be spawned.

To use this, pursue the following steps

  • Add gem “daemons” to your Gemfile
  • Run bundle install
  • Make sure you’ve run rails generate delayed_job
  • If you want to just run all available jobs and exit you can use rake jobs:workoff
  • Work off queues by setting the QUEUE or QUEUES environment variable.
    • QUEUE=tracking rake jobs:work
    • QUEUES=mailers,tasks rake jobs:work

Step# 4

  • Add task to run in background
  • In Controller just call .delay.method(params) on any object and it will be processed in the background.

Example:

UsersController before adding to background job

[code language=”html”]
class UsersController < ApplicationController
def send_email
User.find_each(is_subscribed: true) do |user|
NewsMailer.newsletter_mail(user).deliver
flash[:notice] = "Mail delivered"
redirect_to root_path
end
end
end
[/code]

 
UsersController after adding to background job

[code language=”html”]
class UsersController < ApplicationController
def send_email
User.find_each(is_subscribed: true) do |user|
# add .delay method to add it to background process. In case of mail sending remove the .deliver method to make it work.
NewsMailer.delay.newsletter_mail(user)
flash[:notice] = "Mail delivered"
redirect_to root_path
end
end
end
[/code]

Advantages of implementing above steps:

  • No more waiting for a response, after clicking a link to do a big stuff.
  • Just call .delay.method(params) on any object and it processes in the background.
  • Job objects are serialized to yaml and stored in the delayed_jobs table, so they can be restored by the job runner later.
  • It automatically retries on failure. If a method throws an exception it’s caught and the method reruns later. The method retries up to 25 times at increasingly longer intervals until it passes.
  • “delayed_job” gem maintains log by creating a log file “/log/delayed_job.log”

I am sure this article will give you a clear idea about the way to implement “delayed job” in rails. You can share your thoughts with comments if I have missed anything or if you want to know more.

Do you work on or use Ruby on Rails? Let’s Discuss!

Watch out for the latest Security Patch to deal authentication bypass for RoR

ror41Ruby on Rails framework developers have been continuously releasing security updates since the last two weeks. Its recent updates like 3.0.20 and 2.3.16 versions were to address the remote code execution vulnerability. This was the third security patch released this month. The developers have mentioned that the updates released are extremely important, and have advised the users of 3.0.x and 2.3.x rails framework to update as soon as possible.

The security update will fix the vulnerability in the Rails JSON code. That allowed the hackers to bypass authentication system and inject random SQL into the application database. It occasionally performed denial-of-service attack too. The rails developers have also pointed out that currently it supports only the 2.3.x, 3.1.x, and 3.2.x versions and might release an update for 3.0.x version.

Most recent vulnerability was identified as CVE-2013-0333, which was patched in the framework on 8th of Jan. The Ruby on Rails developers using Rails 2.3 and 3.0 are also advisable to install the new fixes even if they have installed the fix for CVE-2013-0156 earlier.

 

Brief Summery

  • Affected Versions are: 2.3.x, 3.0.x
  • Unaffected Versions are: 3.1.x, 3.2.x, and applications using yajl gem
  • Fixed Versions are: 3.0.20, 2.3.16

How to do tagging in Rails with gem ‘Acts_as_taggable_on’

ror41Tagging is a way to give a keyword and search by that particular keyword. In Rails “acts-as-taggable-on” is one of the popular gem for tagging. With ‘acts_as_taggable_on’, you can tag a single model on several contexts, such as skills, interests, and awards

Below is an example to describe how to implement it in a Rails application:

    Step#1

  • Add the gem to your Gemfile:
  • gem ‘acts-as-taggable-on'
  • Then run the bundle
  • bundle install

    Step#2

  • Run the generator command
  • rails g acts_as_taggable_on:migration
  • Run the migration file
  • rake db:migrate

    This migration will create two tables in the database: tags and taggings.
    Step#3
    Now you have to modify your model where you want to implement tagging.
    For example, we like to implement the tagging on Post model.

  • Add the following codes to the “Post” model to have acts_as_taggable and also add a “tag_list” field to the attr_accessible list.
  • attr_accessible :content, :name, :tag_list
    acts_as_taggable

    Step#4

  • Add a new field to your post form.
  • <%= f.label :tag_list, "Tags (separated by commas)" %>
    <%= f.text_field :tag_list %>

    Step#5

  • Add the following codes, if you want to show the tags for the tagged posts in the listing page:
  • <% @posts.each do |post| %>
    <h2><%= link_to post.name, post %></h2>
    <%= simple_format post.content %>
    <p>
    Tags: <%= raw post.tag_list.map { |t| link_to t, tag_path(t) }.join(', ') %>
    </p>
    <% end %>

    Step#6

  • Modify your route file to get the tags
  • get 'tags/:tag', to: 'posts#index', as: :tag

    Step#7

  • Modify your controller:
  • class PostsController < ApplicationController
    def index
    if params[:tag]
    @posts = Post.tagged_with(params[:tag])
    else
    @posts = Post.all
    end
    end
    end
    

Voila! You have done it.

Validating RSS Feeds in Rails

Rails1FeedValidator is a gem which validates the RSS feeds through SOAP protocol of the W3C Feed Validation service. It helps to find out errors in RSS or ATOM feeds. In Rails app we can do the feed validation by installing the gem.

    Step#1

  • Install the FeedValidator as a gem:
  • gem feedvalidator

    Run the bundler to install the gem
    Step#2

  • Include the require ‘feed_validator’ into your controller
  • Step#3

  • Generate a migration file and edit the file to add the following fields
  • class CreateFeeds < ActiveRecord::Migration
    def self.up
    create_table :feeds do |t|
    t.string :title
    t.timestamps
    end
    end
    def self.down
    drop_table :feeds
    end
    end
    

    Step#4

  • Validate your feed URL in your controller
  • def create
    site_url = params[:feed][:title].sub(/(\/)+$/,'')
    begin
    v = W3C::FeedValidator.new
    if v.validate_url(site_url) && v.valid?
    @feed = Feed.new(:title => site_url)
    @feed.save
    end
    rescue
    # Do nothing
    end
    redirect_to request.referrer
    end