Bird
Raised Fist0
Ruby on Railsframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the Convention over configuration principle in Rails primarily help with?
easy
A. Automatically generating user interface designs
B. Reducing the amount of setup code by following naming rules
C. Making Rails apps run faster by optimizing queries
D. Forcing developers to write detailed configuration files

Solution

  1. Step 1: Understand the principle's goal

    Convention over configuration means Rails guesses what you want if you follow its naming rules.
  2. Step 2: Identify the main benefit

    This reduces the need to write extra setup or configuration code manually.
  3. Final Answer:

    Reducing the amount of setup code by following naming rules -> Option B
  4. Quick Check:

    Convention over configuration = less setup code [OK]
Hint: Think: Rails guesses if you follow rules, so less setup [OK]
Common Mistakes:
  • Confusing it with performance optimization
  • Thinking it forces more configuration files
  • Assuming it auto-generates UI designs
2. Which of the following is the correct Rails convention for naming a model class representing users?
easy
A. class User < ApplicationRecord
B. class users < ApplicationRecord
C. class user < ApplicationRecord
D. class USER < ApplicationRecord

Solution

  1. Step 1: Recall Rails naming conventions for models

    Model class names are singular and start with a capital letter, e.g., User.
  2. Step 2: Check syntax correctness

    class User < ApplicationRecord uses correct class name capitalization and inherits from ApplicationRecord.
  3. Final Answer:

    class User < ApplicationRecord -> Option A
  4. Quick Check:

    Model class names are singular and capitalized [OK]
Hint: Model names are singular and capitalized classes [OK]
Common Mistakes:
  • Using plural or lowercase class names
  • Not capitalizing the class name
  • Using all uppercase letters
3. Given a Rails model named Article, which database table name will Rails expect by convention?
medium
A. articles
B. article
C. Article
D. article_table

Solution

  1. Step 1: Recall Rails table naming convention

    Rails expects database tables to be plural lowercase versions of model names.
  2. Step 2: Apply to the model 'Article'

    The plural lowercase form is 'articles'.
  3. Final Answer:

    articles -> Option A
  4. Quick Check:

    Model 'Article' maps to table 'articles' [OK]
Hint: Model name pluralized lowercase = table name [OK]
Common Mistakes:
  • Using singular table names
  • Using capitalized table names
  • Adding extra suffixes like '_table'
4. You created a model class class Person < ApplicationRecord but named the database table people_data. What is the main issue here?
medium
A. Rails will use the people_data table without problems
B. Rails will automatically find the table despite the name difference
C. Rails will raise an error because the table name does not follow convention
D. Rails will ignore the model and use a default table

Solution

  1. Step 1: Understand default table naming

    Rails expects the table name to be the plural form of the model name, here 'people'.
  2. Step 2: Check mismatch impact

    Since the table is named 'people_data', Rails won't find it automatically and will raise an error unless explicitly told.
  3. Final Answer:

    Rails will raise an error because the table name does not follow convention -> Option C
  4. Quick Check:

    Table name mismatch causes error unless configured [OK]
Hint: Table name must match plural model name or configure explicitly [OK]
Common Mistakes:
  • Assuming Rails guesses any table name
  • Thinking Rails silently ignores the model
  • Believing Rails auto-corrects table names
5. You want to create a Rails controller for managing blog posts. According to convention, which controller class name and file path are correct?
hard
A. class BlogPostController < ApplicationController in app/controllers/blog_post_controller.rb
B. class blogpostscontroller < ApplicationController in app/controllers/blogposts_controller.rb
C. class BlogPosts < ApplicationController in app/controllers/blog_posts.rb
D. class BlogPostsController < ApplicationController in app/controllers/blog_posts_controller.rb

Solution

  1. Step 1: Recall controller naming conventions

    Controllers are plural, camel case with 'Controller' suffix, e.g., BlogPostsController.
  2. Step 2: Recall file path conventions

    File names are snake_case plural with '_controller.rb' suffix, e.g., blog_posts_controller.rb.
  3. Final Answer:

    class BlogPostsController < ApplicationController in app/controllers/blog_posts_controller.rb -> Option D
  4. Quick Check:

    Controller class plural + Controller suffix, file snake_case plural [OK]
Hint: Controller class plural CamelCase + file snake_case plural_controller.rb [OK]
Common Mistakes:
  • Using singular controller class names
  • Incorrect file naming or casing
  • Omitting 'Controller' suffix
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard