100+ Frequently Asked Ruby on Rails Questions

Ruby on Rails is a very popular web development framework and is in high demand too. So many companies and clients are using this framework to build their products. If you are also thinking to prepare for Ruby on Rails interviews then here is 100+ most frequently asked Ruby on Rails questions that can definitely help you. These questions requires both practical and conceptual knowledge to answer properly so if you know answers to all these questions you have better chances to impress your recruiters.

1.What is the difference between has_many :through and has_and_belongs_to_many? Also state which one is better?

2.What are validations in rails? At what moments of an object's lifecycle validations are checked?

3.What do you mean by polymorphic association in rails? When can one use this association?

4.What are scopes in Rails?

5.What is the difference between class methods and scopes? Are they similar?

6.What do you mean by ActiveRecord callbacks? Explain some ActiveRecord callbacks.

7.How can you define custom validations in rails?

8.What do you mean by STI(single table inheritance)? What are its advantages and disadvantages?

9.What do you mean by migrations in Rails? What is the usage of rails migrations?

10.What do you mean by N+1 query? How can you resolve N+1 query? Explain by an example.

11.What is the difference between includes and joins?

12.What do you mean by self_join association in Rails?

13.What do you mean by ORM? Explain.

14.Is it possible to change the convention of naming a table in rails? If yes, how will you do this? Please explain.

15.What do you mean by Rolling back a migration? How can you rollback a specific migration?

16.What are the Relational and Conditional callbacks in ActiveRecord? Explain them.

17.What are transactional callbacks? Explain them.

18.What do you mean by member and collection routes? Explain.

19.What do you know about namespace and scoped routing? What is the difference between both?

20.Explain the difference between webpacker and sprockets.

21.How many types of associations are in rails?

22.What do you mean by partials in Rails? Explain the usage of partials and the way we can pass local variables to a partial.

23.What are delegates in Rails? Explain usage of delegates.

24.What do you mean by helper classes? Explain.

25.What do you mean by mailers? How many ways to pass arguments to a mailer?

26.What do you mean by concerns in Rails? Explain the way of using a concern.

27.Have you ever used sidekiq? Explain how it works in both production and development environments?

28.What is the difference between a sidekiq worker and rails ActiveJob?

29.What do you mean by rake tasks? How can you define/implement custom rake tasks?

30.Do you know about ActiveStorage? How can you use this?

31.Explain strong parameters.

32.How do you pass default arguments to a controller action where you instantiate a new model object?

33.What are turbolinks into rails?

34.What do you mean by API versioning in Rails? Explain when there is a need to change the version of an API?

35.What is the difference between before_save, before_create and before_update?

36.What do you mean by asset pipeline?

37.What do you mean by default_scope? Please explain.

38.Explain routing in rails.

39.What do you mean by filter actions or controller callbacks? Explain.

40.How can you handle ActiveRecord::RecordNotFound exception for all resources?

41.How many gems for the admin backend have you used? Which gem is better and why?

42.You are asked to implement an admin backend for a web application. What solution will you propose? Any gem or custom admin panel? Also explain the reason.

43. What is the difference between save and save!?

44. How can you pass params to a mailer action?

45. Is it possible to replace the schema.rb file in Rails? If yes, how can you do this?

46. What is ActionCable? Explain.

47. How can you implement user authentication using devise and JWT? Explain the process of it.

48. How many form helpers are provided by rails? Tell the names and differences between them.

49. What is the difference between delete and destroy in Rails?

50. How do you organize your controllers? Tell me about the way that you can make a controller thin.

51. What do you mean by sessions in Rails? In what circumstances do you need to use sessions? Explain.

52. What is the find_each method in Rails? Also explain why the .all method is not ideal to use for loading all the instances of a model at once?

53. What is polymorphic association in Rails? When should you actually use a polymorphic association?

54. What is the difference between eager_load and includes methods? And which one is better?

55. Which of the methods is faster between delete and destroy? Explain why?

56. What is the difference between ActiveModel and ActiveRecord?

57. What is the difference between dependent: :destroy and dependent: :delete_all?

58. What is yield in Ruby? What happens if you call the method, which includes yield, without passing a block?

59. What is the difference between Hash and HashWithIndifferentAccess?

60. In Ruby, how many ways to invoke a method? Illustrate with examples.

61. In Ruby, what is the difference between Strings and Symbols? Explain.

62. What do you mean by schema versioning in Rails? When does it change?

63. What do you mean by reversible migrations?

64. How can you run/rollback any specific migration in Rails?

65. When should you use an up and down method instead of a change method inside your migration? Explain by an example.

66. What is shallow nesting of routes and when is preferable to use this?

67. What do you mean by meta Programming in Ruby? Explain how you can implement this in your program?

68. What do you mean by inject method in Ruby?

69. What is the difference between equal? and eql? method in Ruby?

70. What is the advantage of using hash over an array in Ruby?

71. What is the difference between iterators and loops in Ruby?

72. What are accessor methods in Ruby? List and explain accessor methods.

73. What are class level and module level attributes?

74. What is the difference between include and extend in rails?

75. How many template engines are supported by Rails? Which one is your preference and why?

76. What do you mean by singleton (Eigen) class in Ruby?

77. When do you think is the right time to define a helper method inside a controller in Rails?

78. What is your understanding of DRY code? Explain.

79. What is your approach to write a thin controller? Also explain why a controller should be thin and what are the advantages of it?

80. What is the purpose of initializers directory in a rails project?

81. What is the difference between a gem and Rails engine?

82. What do you mean by a rails engine? Explain when we need to use a rails engine? Also if you know, list a few gems which are engines as well.

83. Is it possible to use two identical keys in a hash? What happens if you use two identical keys in a hash?

84. What is the best way to define a foreign key into an existing table in rails?

85. How many rails versions have you worked with? Also list the changes between the rails versions you have worked on.

86. What is the difference between Array and Enumerator?

87. What is your preference for return response for an API? Jbuilder or ActiveModel serializers? And why?

88. What are the differences between lambda and proc?

89. What do you mean by argumented scopes? When do you need to write argumented scopes?

90. What is the difference between update and update_attribute method?

91. What is the difference between :allow_nil and :allow_blank validation options?

92. What do you mean by strict and conditional validations?

93. When do you need to skip callbacks? List a few of the methods, by using them you can skip callbacks.

94. Is it possible to send emails without rendering a template in Rails? If yes, how will you do this?

95. What is the difference between deliver_now and deliver_later methods for sending emails?

96. What do you mean by upsert?

97. What do you mean by session storage in Rails? Explain.

98. What do you mean by session hijacking?

99. What are the main features of the asset pipeline in Rails?

100. What do you mean by page caching, action caching and fragment caching?

101. Why does ruby not support method overloading?

102. What are modules in Ruby? How can you differentiate class and instance methods in a module?

103. What is the difference between after_save and after_commit?

104. What are mixins in Ruby?

105. What do you mean by the send method in Ruby?

106. Have you worked with sidekiq? Why is it used for?

107. What is the difference between the basic version of sidekiq and sidekiq pro?

108. What are perform and perform_async methods in sidekiq? What is the difference between them?

109. What is the difference between let and let! in RSpec?

110. What are the callbacks? Explain for both the model and controller.

111. What is the difference between uniq and distinct in rails?

112. In rails how you will get objects with at least one child?

113. In what cases the change method is not reversible in a Rails migration?

114. What happens if you do not provide the column type in the remove_column migration?

115. What happens if you rollback a change_column migration within the change method?

116. What is the difference between preload and includes?

117. How many ways to eager loading the associations?

118. What do you mean by content_for in Rails?

119. What do you mean by sanitizing params in Rails?

120. What is the difference between render and redirect in Rails?

121. What is the difference between module and concerns in Rails?

122. What is cattr_accessor ?

123. What is difference between cattr_accessor and attr_accessor ?

124. What is difference between sub and gsub method in Ruby ?

125. How to set a custom primary key in rails model other than id?

126. How to provide custom name to a model table in rails ?

127. What is the difference between is_a? and instance_of? methods in Ruby? Which one you will prefer?

APPSIMPACT Academy

Ruby on Rails is a very popular and most productive web application development framework. At APPSIMPACT Academy we provide best content to learn Ruby on Rails framework.

Questions & Answers
What is the difference between instance variables and local variables? What is initialize() method in Ruby? What are getter and setter methods in Ruby? Comparision between rails 4, 5 and 6 What is difference between sub and gsub in Ruby? How to recreate flatten method in Ruby using recursion?