Challenge - 5 Problems
Rails Structure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens if you place a Rails controller outside the app/controllers folder?
In a Rails app, controllers are expected to be inside
app/controllers. What will happen if you put a controller file in lib/controllers instead?Attempts:
2 left
💡 Hint
Think about how Rails autoloads files based on folder structure.
✗ Incorrect
Rails uses a convention to autoload controllers from the
app/controllers folder. Placing controllers elsewhere means Rails won't find them automatically, leading to routing errors.📝 Syntax
intermediate2:00remaining
Identify the error caused by incorrect model naming in Rails
Given a model file named
user_profile.rb inside app/models but the class inside is named class Userprofile < ApplicationRecord, what error will Rails raise?Ruby on Rails
class Userprofile < ApplicationRecord
endAttempts:
2 left
💡 Hint
Rails expects class names to match file names in camel case.
✗ Incorrect
Rails expects the class name to be
UserProfile matching the file user_profile.rb. Mismatched names cause Rails to fail to find the constant, raising a NameError.❓ state_output
advanced2:00remaining
What is the output when a view template is misplaced in Rails?
If you place a view template
index.html.erb inside app/views/shared but the controller action expects it in app/views/posts, what will Rails render when visiting the index action of PostsController?Attempts:
2 left
💡 Hint
Rails looks for views in folders matching controller names.
✗ Incorrect
Rails expects views to be in folders named after the controller. If the template is misplaced, Rails raises a MissingTemplate error.
🔧 Debug
advanced2:00remaining
Why does Rails fail to load a helper module placed outside the helpers folder?
You created a helper module
app/lib/custom_helper.rb and included it in a view, but Rails raises an error saying the helper is undefined. Why?Ruby on Rails
module CustomHelper def greet 'Hello' end end
Attempts:
2 left
💡 Hint
Consider Rails autoload paths and conventions for helpers.
✗ Incorrect
Rails autoloads helpers only from
app/helpers. Placing helpers elsewhere requires manual loading or configuration.🧠 Conceptual
expert3:00remaining
Why is following Rails folder structure conventions critical for large projects?
Imagine a large Rails project with many developers. Why is it important to strictly follow Rails folder structure conventions?
Attempts:
2 left
💡 Hint
Think about teamwork and Rails conventions.
✗ Incorrect
Following conventions helps Rails autoload code properly, reduces errors, and makes it easier for developers to navigate and maintain the codebase.