0% found this document useful (0 votes)
19 views5 pages

Ruby On Rails Top 50 Questions For Freshers

The document provides a comprehensive list of the top 50 Ruby on Rails interview questions and answers aimed at freshers. It covers fundamental concepts such as Ruby, MVC architecture, ActiveRecord, migrations, and RESTful routes, as well as practical commands for creating applications, models, and controllers. Additionally, it addresses topics like validations, testing, and deployment strategies for Rails applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Ruby On Rails Top 50 Questions For Freshers

The document provides a comprehensive list of the top 50 Ruby on Rails interview questions and answers aimed at freshers. It covers fundamental concepts such as Ruby, MVC architecture, ActiveRecord, migrations, and RESTful routes, as well as practical commands for creating applications, models, and controllers. Additionally, it addresses topics like validations, testing, and deployment strategies for Rails applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Top 50 Ruby on Rails Interview Questions and Answers (For Freshers)

1. What is Ruby on Rails?

Ruby on Rails is a web application framework written in Ruby. It follows the MVC

(Model-View-Controller) architecture.

2. What is Ruby?

Ruby is a dynamic, open-source programming language focused on simplicity and productivity.

3. What is MVC?

MVC stands for Model-View-Controller. It separates the application logic (Model), UI (View), and

input control (Controller).

4. What are Gems in Rails?

Gems are libraries or packages in Ruby that extend the functionality of your app.

5. How do you create a new Rails application?

`rails new app_name`

6. What is ActiveRecord?

It's the ORM layer in Rails that helps in database interaction using Ruby classes.

7. What is a migration in Rails?

Migrations are used to modify the database schema over time in a consistent and easy way.

8. What command generates a model in Rails?

`rails generate model ModelName field1:type field2:type`

9. How do you start a Rails server?

`rails server` or `rails s`

10. What is the purpose of the routes file?

It defines the URL patterns and maps them to controllers/actions.

11. How do you create a controller in Rails?


`rails generate controller ControllerName`

12. Where are the views located?

In the `app/views` folder, grouped by controller name.

13. How do you render a view?

`render :view_name` inside a controller action.

14. What is the difference between render and redirect_to?

`render` displays a view, `redirect_to` sends a new HTTP request to a different action or controller.

15. What is a partial in Rails views?

A partial is a reusable view fragment prefixed with an underscore (`_`).

16. How do you include a partial?

`<%= render 'partial_name' %>`

17. What is a helper in Rails?

Helpers are methods used in views to format data or add logic.

18. How do you define model relationships (e.g., one-to-many)?

`has_many`, `belongs_to`, `has_one`, etc.

19. What does rails db:migrate do?

Applies pending migrations to the database.

20. What is form_with in Rails?

A helper to generate forms that work with models or custom URLs.

21. What are RESTful routes?

Routes that follow REST principles - using HTTP verbs like GET, POST, PATCH, DELETE.

22. How do you define resources in routes?

`resources :model_name`

23. How to define a root path?


`root 'controller#action'`

24. What is params in Rails?

A hash that stores data from the request (form data, URL params, etc.).

25. What are strong parameters?

A security feature to prevent mass assignment. You whitelist params using

`params.require(...).permit(...)`.

26. How to retrieve all records from a model?

`Model.all`

27. How to find a record by ID?

`Model.find(id)`

28. How to create a new record?

`Model.create(attribute: value)`

29. How to update a record?

`model.update(attribute: value)`

30. How to delete a record?

`model.destroy`

31. What are validations in Rails?

Constraints added to model fields, e.g., `validates :name, presence: true`

32. How do you define a uniqueness validation?

`validates :email, uniqueness: true`

33. What are callbacks in Rails?

Methods triggered during an object-s lifecycle, like `before_save`, `after_create`.

34. What is the difference between new and create in ActiveRecord?

`new` instantiates an object, `create` instantiates and saves it.


35. How do you run the Rails console?

`rails console` or `rails c`

36. What is the purpose of the Gemfile?

It manages dependencies for the Rails application.

37. How do you install dependencies?

`bundle install`

38. What is the bin/rails command?

It's a wrapper for running Rails commands.

39. How do you write a test in Rails?

Using `test` or `RSpec` frameworks (e.g., `assert` or `expect` syntax).

40. What is the difference between development, test, and production environments?

These define different settings and databases for each stage of the app lifecycle.

41. What is scaffold in Rails?

It generates model, views, controller, and routes in one command.

42. How do you create a scaffold?

`rails generate scaffold ModelName field:type`

43. What is flash in Rails?

A hash used to send temporary messages (e.g., success, error) between actions and views.

44. What is CSRF and how does Rails handle it?

CSRF (Cross-Site Request Forgery) is prevented in Rails via authenticity tokens in forms.

45. What is Turbolinks?

A gem that speeds up navigation by using AJAX to load new pages.

46. How do you use layouts in Rails?

Layouts are wrappers for views, defined in `app/views/layouts`.


47. What is yield in layout files?

Placeholder where the view content is injected.

48. What is an asset pipeline?

A system for managing JavaScript, CSS, and image files.

49. How do you debug in Rails?

Use `byebug`, `logger.debug`, or `rails console`.

50. How do you deploy a Rails app?

Options include using Heroku, Capistrano, or Docker.

You might also like