Try to solve 3 Ruby on Rails interview questions below. Hints can help you find answers to questions you are having trouble with.

1. Contacts Migration

Database migrations
   
Easy  

Select all statements that are correct after the following migration has been executed:

class ContactsMigration < ActiveRecord::Migration
  def change
    create_table :contacts do |t|
      t.string :name
      t.integer :telephone_number
      t.text :address, null: false
      t.timestamps
    end
  end
end

(Select all acceptable answers.)

The contacts.name field may be null.
The contacts table has no index.
The table called contacts contains four different data types.
The table called contacts contains four different fields.
The contacts.address field may be null.
   


2. Employee Search

Database abstraction
   
Easy  

A company database contains the following table, in which id is the primary key:

employees

id name age
1 Steve 21
2 John 44
3 Amy 26
4 Marcus 44

Select all the statements that return only the employee with name "John" (id = 2).

(Select all acceptable answers.)

Employee.find("John")
Employee.find_by(name: "John")
Employee.where(name: "John").first
Employee.where("age > 30")
Employee.not.where(name: ["Steve", "Amy", "Marcus"])
   


3. Record Route

HTTP Routing
   
Easy  

Consider the following controller and view definitions:

class RecordsController < ApplicationController
  def update
    @record = Record.find(params[:id])
    @record.update(record_params)
  end
end
<%= form_for @record do |f| %>
<%= render 'form', f: f %>
<% end %>

Select the statements that can be used to update a record.

(Select all acceptable answers.)

write '/records/:id', to: 'records#update'
put '/records/:id', to: 'records#update'
patch '/records/:id', to: 'records#update'
post '/records/:id', to: 'records#update'
resource :records, only: [:update]
   


If you feel ready, take one of our timed public Ruby on Rails Interview Questions tests:
Ruby

Ruby on Rails Online Test (Easy)

Not exactly what you are looking for? Go to our For Jobseekers section.