Rosalyn  Maggio

Rosalyn Maggio


12 Most Asked Questions About Ruby On Rails

Ruby on Rails is a server-side web application development tool. Currently, it is one of the most popular frameworks and easy to learn. Even if it is easy to learn, programmers still get confused or get stuck at some point. Many questions start to arise and they look for the answers. So, we have prepared a list of 12 most asked questions about Ruby on Rails along with answers.


12 Most Asked Questions About Ruby on Rails

1. How to rename a database column in a Ruby on Rails migration?

2. How to understand nil vs. empty vs. blank in Rails (and Ruby)?

3. Why do people use Heroku when AWS is present? What distinguishes Heroku from AWS?

4. How to get the current absolute URL in Ruby on Rails?

5. Understanding the Rails Authenticity Token

6. How to rollback a specific migration?

7. How to get a random number in Ruby?

8. How to use concerns in Rails 4?

9. How to check if a specific key is present in a hash or not?

10. How to “pretty” format JSON output in Ruby on Rails?

11. Installing PostgreSQL on Ubuntu for Ruby on Rails

12. Difference between collection route and member route in ruby on rails?

1. How to rename a database column in a Ruby on Rails migration?


rename_column :table, :old_column, :new_column

You’ll probably want to create a separate migration to do this. (Rename FixColumnName as you will.):

script/generate migration FixColumnName

## creates db/migrate/xxxxxxxxxx_fix_column_name.rb

Then edit the migration to do your will:

## db/migrate/xxxxxxxxxx_fix_column_name.rb
class FixColumnName < ActiveRecord::Migration
  def self.up
    rename_column :table_name, :old_column, :new_column

  def self.down
    ## rename back if you need or do something else or do nothing

For Rails 3.1 use:

While the up and down methods still apply, Rails 3.1 receives a change method that “knows how to migrate your database and reverse it when the migration is rolled back without the need to write a separate down method”.

rails g migration FixColumnName

class FixColumnName < ActiveRecord::Migration
  def change
    rename_column :table_name, :old_column, :new_column

If you happen to have a whole bunch of columns to rename or something that would have required repeating the table name over and over again:

rename_column :table_name, :old_column1, :new_column1
rename_column :table_name, :old_column2, :new_column2

You could use change_table to keep things a little neater:

class FixColumnNames < ActiveRecord::Migration
  def change
    change_table :table_name do |t|
      t.rename :old_column1, :new_column1
      t.rename :old_column2, :new_column2

Then just db:migrate as usual or however, you go about your business.

For Rails 4:

While creating a Migration for renaming a column, Rails 4 generates a change method instead of up and down as mentioned in the above section. The generated change method is:

$ > rails g migration ChangeColumnName

which will create a migration file similar to:

class ChangeColumnName < ActiveRecord::Migration

def change

rename_column :table_name, :old_column, :new_column



Alternative Answer:

You can also use rake db:rollback, then edit your migration and again run rake db:migrate.

However, if you have data in the column you don’t want to lose, then use rename_column.

2. How to understand nil vs. empty vs. blank in Rails (and Ruby)?


.nil? can be used on any object and is true if the object is nil.

.empty? can be used on strings, arrays, and hashes and returns true if:

  • String length == 0
  • Array length == 0
  • Hash length == 0

Running .empty? on something that is nil will throw a NoMethodError.

That is where .blank? comes in. It is implemented by Rails and will operate on any object as well as work like .empty? on strings, arrays, and hashes.

nil.blank? == true
false.blank? == true
[].blank? == true
{}.blank? == true
"".blank? == true
5.blank? == false
0.blank? == false

.blank? also evaluates true on strings which are non-empty but contain only whitespace:

"  ".blank? == true
"  ".empty? == false

Rails also provides .present?, which returns the negation of .blank?.

Array gotcha: blank? will return false even if all elements of an array are blank. To determine blankness in this case, use all? with blank?, for example:

[ nil, '' ].blank? == false

[ nil, '' ].all? &:blank? == true

Alternative Answer:

This table will help you understand better:

enter image description here

blank?, present? are provided by Rails.

3. Why do people use Heroku when AWS is present? What distinguishes Heroku from AWS?


AWS / Heroku are both free for small hobby projects (to start with).

If you want to start an app right away, without much customization of the architecture, then choose Heroku.

If you want to focus on the architecture and to be able to use different web servers, then choose AWS. AWS is more time-consuming based on what service/product you choose but can be worth it. AWS also comes with many plugin services and products.


  • Platform as a Service (PAAS)
  • Good documentation
  • Has built-in tools and architecture.
  • Limited control over architecture while designing the app.
  • Deployment is taken care of (automatic via GitHub or manual via git commands or CLI).
  • Not time-consuming.


  • Infrastructure as a Service (IAAS)
  • Versatile – has many products such as EC2, LAMBDA, EMR, etc.
  • Can use a Dedicated instance for more control over the architecture, such as choosing the OS, software version, etc. There is more than one backend layer.
  • Elastic Beanstalk is a feature similar to Heroku’s PAAS.
  • Can use the automated deployment, or roll your own.

4. How to get the current absolute URL in Ruby on Rails?


For Rails 3.2 or Rails 4+

You should use request.original_url to get the current URL.

This method is documented at original_url method, but if you’re curious, the implementation is:

def original_url
  base_url + original_fullpath

For Rails 3:

You can write "#{request.protocol}#{request.host_with_port}#{request.fullpath}", since request.url is now deprecated.

For Rails 2:

You can write request.url instead of request.request_uri. This combines the protocol (usually http://) with the host, and request_uri to give you the full address.

Alternative Answer:

You could use url_for(only_path: false)

5. Understanding the Rails Authenticity Token


What happens

When the user views a form to create, update, or destroy a resource, the Rails app creates a random authenticity_token, stores this token in the session, and places it in a hidden field in the form. When the user submits the form, Rails looks for the authenticity_token, compares it to the one stored in the session, and if they match the request is allowed to continue.

Why it happens

Since the authenticity token is stored in the session, the client cannot know its value. This prevents people from submitting forms to a Rails app without viewing the form within that app itself. Imagine that you are using service A, you logged into the service and everything is ok. Now imagine that you went to use service B, and you saw a picture you like and pressed on the picture to view a larger size of it. Now, if some evil code was there at service B, it might send a request to service A (which you are logged into), and ask to delete your account, by sending a request to This is what is known as CSRF (Cross Site Request Forgery).

If service A is using authenticity tokens, this attack vector is no longer applicable, since the request from service B would not contain the correct authenticity token, and will not be allowed to continue.

API docs describes details about meta tag:

CSRF protection is turned on with the protect_from_forgery method, which checks the token and resets the session if it doesn’t match what was expected. A call to this method is generated for new Rails applications by default. The token parameter is named authenticity_token by default. The name and value of this token must be added to every layout that renders forms by including csrf_meta_tags in the HTML head.


Keep in mind, Rails only verifies not idempotent methods (POST, PUT/PATCH and DELETE). GET request are not checked for authenticity token. Why? because the HTTP specification states that GET requests is idempotent and should not create, alter, or destroy resources at the server, and the request should be idempotent (if you run the same command multiple times, you should get the same result every time).

Also, the real implementation is a bit more complicated as defined in the beginning, ensuring better security. Rails does not issue the same stored token with every form. Neither does it generate and store a different token every time. It generates and stores a cryptographic hash in a session and issues new cryptographic tokens, which can be matched against the stored one, every time a page is rendered. See request_forgery_protection.rb.


Use authenticity_token to protect your not idempotent methods (POST, PUT/PATCH, and DELETE). Also, make sure not to allow any GET requests that could potentially modify resources on the server.

Alternative Answer:

The authenticity token is designed so that you know your form is being submitted from your website. It is generated from the machine on which it runs with a unique identifier that only your machine can know, thus helping prevent cross-site request forgery attacks.

If you are simply having difficulty with rails denying your AJAX script access, you can use

<%= form_authenticity_token %>

to generate the correct token when you are creating your form.

You can read more about it in the documentation.

#ruby #ruby-on-rails #programming #developer #interview-questions

What is GEEK

Buddha Community

12 Most Asked Questions About Ruby On Rails

Ruby on Rails Development Services | Ruby on Rails Development

Ruby on Rails is a development tool that offers Web & Mobile App Developers a structure for all the codes they write resulting in time-saving with all the common repetitive tasks during the development stage.

Want to build a Website or Mobile App with Ruby on Rails Framework

Connect with WebClues Infotech, the top Web & Mobile App development company that has served more than 600 clients worldwide. After serving them with our services WebClues Infotech is ready to serve you in fulfilling your Web & Mobile App Development Requirements.

Want to know more about development on the Ruby on Rails framework?


Share your requirements

View Portfolio

#ruby on rails development services #ruby on rails development #ruby on rails web development company #ruby on rails development company #hire ruby on rails developer #hire ruby on rails developers

Emily Johnson


Hire Ruby on Rails Developer | Hire RoR Developer

Are you looking for Ruby on Rails developers for building next-generation web applications?

Bacancy Technology is top-notch Ruby on Rails development company providing world’s best Ruby On Rails Development Services With 8+ Years Of Experience. Hire Ruby on Rails developer for web application that reflects cutting-edge solutions for your business needs. Access 40+ RoR developers. save upto 40% on development cost.

Get top Ruby on Rails developers from Bacancy Technology, contact now and hire your choice of developer’s within 48 Hours, to know more about our RoR services & pricing:

ruby on rails development

#hire ruby on rails developer #ruby on rails developer #ruby on rails development company #ruby on rails development services #hire ror developer #ruby on rails development

Shardul Bhatt

Shardul Bhatt


Why should we use Ruby on Rails for Software Development?

What is Rails, Ruby on Rails?

Rails is a server-side web application development framework written in the Ruby programming language. Its emergence in 2005 has influenced and impacted web application development to a vast range, including but not limited to seamless database tables, migrations, and scaffolding of views. In the simplest understanding, Rails is a highly productive and intuitive software developer. 

Websites and applications of any complexity can be achieved with Ruby on Rails. The software is designed to perceive the needs of ruby on rails developers and encourage them with the best way out. It is designed to allow developers to write lesser code while spiking productivity much more than any other framework or language. Ruby on Rails rapid application development offers everyday web development tasks easier and uniquely out-of-the-box, both with the same effectiveness.

The Ruby on Rails framework is based on two philosophies:


  • Don’t Repeat Yourself (DRY): It is a software development principle that ensures that every piece or entity of knowledge must be assigned with a single and unambiguous representation within a development system.

    It not only reduces the need to write lengthy codes but also eliminates the repetitive writing of codes. As a result, it provides a much more manageable web app development with the least possible bugs.


  • Convention over Configuration (CoC): It indicates the highly opinionated feature that the Ruby on Rails framework possesses. It offers ready-made solutions or the “best way out” for many tasks in a web application and defaults them to the convention without the need for external specification. The programmer using the software is required to specify only the unconventional aspects of the web application. 

Some of the commonly known websites built by the Ruby on Rails software developers are Instacart, Scribd, Shopify, Github, ConvertKit, Soundcloud, GoodReads, Airbnb. It finds its application in Sa-as Solutions, Social Networking Platforms, Dating websites, Stock Exchange Platforms, etc.  

Read more: Why Ruby on Rails is Perfect for eCommerce Web Development

Why use Ruby on Rails: The multifold benefits

  • Community and its abundant resources 

    • There is a large community that is dedicated to Ruby on Rails that keeps it up-to-date and indeed encourages its family of developers to continue using it. They make sure the benefits are soaring with every update they make. 

    • The community is committed to developing several ready-to-use code packages, commonly known as gems, for its users. They discuss and announce new project launches, help each other with queries, and engage in framework discussions and betterment. While Ruby on Rails helps developers in rapid application development, it also connects and grows businesses together.

  • Project Scalability

    • To talk about scalability, we indicate the ability to grow and manage more and more user requests per minute (RPM). However, this depends on the architecture rather than the framework. The right architecture of Ruby on Rails web application development allows it to write bulky codes and programs as compared to early-stage difficulties with scalability. 

    • It uses the Representational State Transfer (REST) architecture. This will enable Rails to create efficient web applications based on Rails 6, launched last year in 2020, which addresses most scalability issues. The portable components are agile and help in a better understanding of new requirements and needful adaptations for any business. The framework and architecture allow both vertical and horizontal scalability.

  • Fast Application Development and Cost Effectiveness

    • Ruby on Rails is lucid, logical, and has lean code requirements, thereby cutting down redundancy and improving the overall development speed. Lesser amount of code is proportional to lesser time investment with optimal results. The more time it takes for development, the more expensive it becomes for the end customers.

    • Considering the ready-made code modules/packages (gems) available, Ruby on Rails development company will less time and money are spent creating and modifying Rails websites and applications. Another advantage that has made Ruby on Rails super attractive for startups is its use of Model-View-Controller (MVC) architecture. It has a component separation scheme that speeds up the web development process and fixes any errors that occur.  

  • Data Protection

    • Rails framework and the Ruby on Rails community put in a lot of efforts for data protection and security of its customer base. It is also one of the efficient frameworks for developing database-backed applications. 

    • The developers at Ruby on Rails cover many aspects of cybersecurity, including encryptions of  passwords, credit card information, and users’ personal database. Special measures are taken to prevent the framework from SQL injections and XSS attacks. 

  • Ruby on Rails Enterprise Application Development

    • Ruby on Rails simplifies the daily operations and lowers the cost of enterprise app developments. The prominent features include data management, seamless updating of applications, easy and efficient code development, and high scalability, as discussed above. 

    • Ruby on Rails enterprise application development is preferred by companies and is slightly cost-intensive. It can be easily integrated with third-party apps like Oracle Business, Oracle, Windows services, and others. Ruby enterprise app development allows the developers and programmers to solve the problems at the root level, given its transparency.

Ruby on Rails V/S Django

Checkout Blog on Django vs Ruby on Rails Comparison

Bottom Line

There are several reasons to prefer Ruby on Rails discussed above and extend further to early detection of errors, reduced time to market, and easy adaptation for API developments. It makes web programming much easier and simplifies website building of any complexity. Its flexibility and acceptance among new developers and programmers make it the perfect, one-stop choice for software application development company in 2021. 


#ruby on rails examples #ruby on rails rapid application development #ruby on rails web application development #ruby on rails software developer #ruby on rails enterprise application development

Emily Johnson


How You Can Reduce Ruby on Rails Maintenance Cost?

#ruby on rails maintenance cost #ruby on rails maintenance #ruby on rails #ror #ruby #rails

Shardul Bhatt

Shardul Bhatt


3 projects where Ruby on Rails Web Development might be WRONG for you

Ruby on Rails has been a popular web development framework for building reliable and scalable web applications. With Ruby on Rails development services, you can create a feature-rich web application at a rapid pace, making it the right choice of framework for startups.

Most technically sound people and CTOs know when to use Ruby on Rails for web development. They are well-aware of situations that call for Ruby on Rails application development.

But there are several cases where Ruby on Rails web application might be the wrong way to go for you. In such situations, you must explore Django frameworks, Laravel web development framework, and other frameworks for your web application.

If you can determine when Ruby on Rails web development framework is WRONG for your business, you can save yourself from a lot of trouble.

Read more: Why Ruby on Rails is Perfect for eCommerce Web Development

3 projects where you should avoid using Ruby on Rails for web development

There are multiple benefits of Ruby on Rails web development. However, it is not a solution to all your web development needs. Here are the three projects in which you should avoid Ruby on Rails agile web development - 


  • Better frameworks available
    When you know that your project needs a better and scalable framework like Django, you should avoid using Ruby on Rails web application development at all costs. While Ruby web apps are scalable, Django and Python are much more effective for apps that need to handle massive traffic.

    Similarly, If you want to work with Machine Learning and statistics, then Ruby web programming should not be your first choice. While there are excellent libraries like JRuby, they are not as efficient as the libraries in Django.

  • Massive codebase
    When you know that your project requires a massive codebase with lots of programmers working on it, then Ruby on Rails for web application is definitely the wrong choice. It would make the application structure unstable as it is designed for small and medium-sized applications.

    You can have several exceptions for Ruby on Rails scaling, but it is done with the help of different tools. It is also not a smart move to build a Ruby on Rails web app with a team of 100 Ruby web programmers.

  • Technical execution
    If your web application project focuses more on technical execution than Ruby on Rails agile web development should be avoided as a possibility. Rails is a fail-fast framework that emphasizes rapid web development.

    When your product has a lot of technical requirements, Ruby web programming can really throw-off your web development project. Even when you don’t want to use RubyGems, the framework assumes that you want to and might add to a lot of extra dependencies.


Ruby on Rails web development is fantastic everywhere else

Apart from the three projects mentioned-above, Ruby on Rails for web development is an amazing choice for all kinds of web application projects.  

If you are a startup that believes in building and breaking quickly, then Ruby on Rails agile web development should be your first choice. And when it comes to scaling, the framework can support you by handling thousands of user requests. 

Ruby on Rails web applications are going to gain popularity as more businesses look for rapid product development. At BoTree Technologies, we have a team of Ruby on Rails developers that work towards increasing your operational efficiency through world-class Ruby on Rails applications.



#ruby on rails #ruby on rails web development #ruby on rails development services #ruby on rails development company