Home / Interview / Rails :: General Questions

Interview :: Rails

31)

Write the command to run the migration?

32)

How does router work in Rails?

The Rails router recognizes URLs and dispatches them to a controller's action. It also generates paths and URLs. Rails router deals with URLs differently from other language routers. It determines controller, parameters, and action for the request.

Main purpose of Rails routers is:

  • Connecting URLs to code
  • Generating paths and URLs from code

33)

Explain REST in Rails routes?

REST is very beneficial to understand routes in Rails. It stands for Representational State Transfer. Several HTTP methods are used with REST to represent the types of actions performed by the user or application.

34)

Explain some features of nested scaffolding?

The Nested scaffold is the command that generates a set of correctly working nested resource for Rails 4.2 and 5.

Features

  • Generates a nested child resource with a single command
  • Generates a beautifully working bunch of code
  • Automatically generates appropriate model associations for ActiveRecord
  • Haml ready

35)

In how many ways you can create Rails layout HTTP response?

There are three ways to create an HTTP response from the controller's point of view:

  • Call render to create a full response to send back to the browser
  • Call redirect_to to send an HTTP redirect status code to the browser
  • Call head to create a response to end back to the browser

36)

Explain the importance of yield statement in Rails?

The yield statement in Rails decides where to render the content for the action in the layout. If there is no yield statement in the layout, the layout file itself will be rendered, but additional content into the action templates will not be correctly placed within the layout.

37)

How many filters are there in Rails?

Rails filters are methods that run before or after a controller's action method is executed. Rails support three types of filter methods:

  • Before filters
  • After filters
  • Around filters

38)

How can you protect filter methods in Rails?

All the Ruby methods have at least one of these protection level.

  • Public: These methods are accessible from any external class or method that uses the same class in which they are defined.
  • Protected: These methods are accessible only within the class in which they are defined and in the classes that inherit from the class in which they are defined.
  • Private: These methods are only accessible within the class in which they are defined.

39)

Explain testing in Rails?

Rails also use a separate database for testing. Rails use Ruby Test::A unit testing library. Rails application test is usually run using Rake utility.

Rails support three types of tests:

  • functional
  • integration
  • unit tests

40)

Explain Rails caching levels?

Rails caching is available at three levels of granularity:

  • Page
  • Action
  • Fragment