0
0
Ruby on Railsframework~20 mins

Convention over configuration principle in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Convention Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Rails Naming Conventions
In Rails, which file name will Rails automatically associate with the UsersController class following the convention over configuration principle?
Ausers_controller.rb
BUsersController.rb
Cuser_controller.rb
Duserscontroller.rb
Attempts:
2 left
💡 Hint
Think about how Rails expects controller files to be named in snake_case matching the controller class name.
component_behavior
intermediate
2:00remaining
Default Database Table Name for a Model
Given a Rails model class named ProductCategory, what is the default database table name Rails will use without any configuration?
Aproduct_categories
Bproductcategory
Cproduct_category
DProductCategories
Attempts:
2 left
💡 Hint
Rails pluralizes and snake_cases model class names to get table names.
📝 Syntax
advanced
2:00remaining
Identifying the Correct Route Helper Method
In a Rails app with a resource declared as resources :orders, which helper method will generate the path to the new order form following Rails conventions?
Aorder_new_path
Bcreate_order_path
Cnew_order_path
Dorders_new_path
Attempts:
2 left
💡 Hint
Rails uses a specific pattern for new resource routes: new__path.
🔧 Debug
advanced
2:00remaining
Why Does This Rails View Template Not Render?
You have a controller named ArticlesController. You created a view template named show.html.erb inside the folder app/views/article. Why does Rails not render this template by default?
AThe template file should be named show.html.html
BRails requires the template to be in app/views/shared
CThe controller name should be ArticleController
DThe folder name should be plural: app/views/articles
Attempts:
2 left
💡 Hint
Check the folder naming convention for views matching controller names.
state_output
expert
3:00remaining
Effect of Skipping Convention in Model Associations
Consider these two Rails models:

class User < ApplicationRecord
has_many :posts
end


class Post < ApplicationRecord
belongs_to :author, class_name: 'User'
end


What will happen if you try to access post.author without specifying the foreign key in the Post model, assuming the posts table has a user_id column?
ARails will use user_id automatically for author association
BRails will raise an error because it expects author_id column by default
CRails will return nil because the association is not configured properly
DRails will correctly find the user because of class_name and user_id column
Attempts:
2 left
💡 Hint
Think about how Rails infers foreign keys from association names.