0
0
Ruby on Railsframework~20 mins

First Rails application - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Beginner Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Rails controller action render?
Consider this Rails controller code. What will the browser display when visiting the index action?
Ruby on Rails
class ArticlesController < ApplicationController
  def index
    @articles = ['Ruby', 'Rails', 'MVC']
  end
end
AA plain page showing the list: Ruby, Rails, MVC
BA JSON response with the articles array
CA blank page because no view template is provided
DAn error because there is no explicit render call
Attempts:
2 left
💡 Hint
Rails automatically renders a view matching the action name if no render call is given.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this Rails route definition
Which option correctly fixes the syntax error in this routes file snippet?
Ruby on Rails
Rails.application.routes.draw do
  get 'welcome/index'
  root to: 'welcome#index'
  resources :articles
  get 'articles/show/:id' => 'articles#show'
end
AReplace <code>root to: 'welcome#index'</code> with <code>root 'welcome#index'</code>
BAdd a comma after <code>resources :articles</code>
CChange <code>get 'articles/show/:id' => 'articles#show'</code> to <code>get 'articles/:id' => 'articles#show'</code>
DRemove the <code>get 'welcome/index'</code> line
Attempts:
2 left
💡 Hint
Check the URL pattern for the show action in RESTful routes.
state_output
advanced
2:00remaining
What is the output of this Rails view code?
Given the controller sets @name = 'Alice', what will this ERB template output?
Ruby on Rails
<h1>Welcome, <%= @name.upcase %>!</h1>
<p>Today is <%= Date.today.strftime('%A') %>.</p>
A<h1>Welcome, ALICE!</h1><p>Today is Monday.</p>
B<h1>Welcome, Alice!</h1><p>Today is Monday.</p>
C<h1>Welcome, ALICE!</h1><p>Today is <%= Date.today.strftime('%A') %>.</p>
DAn error because <code>Date</code> is not available in views
Attempts:
2 left
💡 Hint
ERB evaluates Ruby code inside <%= %> and Date is accessible in views.
🔧 Debug
advanced
2:00remaining
Why does this Rails form not submit data?
This form in a Rails view does not send data to the controller. What is the cause?
Ruby on Rails
<%= form_with url: articles_path, method: :post do %>
  <%= text_field_tag :title %>
  <%= submit_tag 'Create' %>
<% end %>
AThe form block is missing a variable for the form builder
BThe form_with helper uses remote: true by default, so no page reload occurs
CThe text_field_tag is not inside the form block properly
DThe form_with helper requires a model object to submit data
Attempts:
2 left
💡 Hint
Check the default behavior of form_with regarding remote submission.
🧠 Conceptual
expert
2:00remaining
What is the role of the ApplicationController in a Rails app?
Choose the best description of ApplicationController in a Rails application.
AIt defines the routes and URL mappings for the application
BIt handles database connections and queries for all models
CIt is the main view template that all pages render by default
DIt is the base controller that other controllers inherit from, sharing common behavior and filters
Attempts:
2 left
💡 Hint
Think about inheritance and shared code in controllers.