0
0
Ruby on Railsframework~10 mins

Why Rails API mode exists - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new Rails API-only application.

Ruby on Rails
rails new my_api_app --[1]
Drag options to blanks, or click blank then click option'
Afull
Bminimal
Capi
Dweb
Attempts:
3 left
💡 Hint
Common Mistakes
Using --full creates a full Rails app with views and assets.
Using --web is not a valid Rails new flag.
Using --minimal is not a recognized option.
2fill in blank
medium

Complete the sentence explaining why Rails API mode excludes some features.

Ruby on Rails
Rails API mode excludes [1] and assets to make the app smaller and faster.
Drag options to blanks, or click blank then click option'
Aviews
Bmigrations
Ccontrollers
Dmodels
Attempts:
3 left
💡 Hint
Common Mistakes
Thinking models are excluded, but models are still used.
Controllers are still needed to handle requests.
Migrations are part of database setup and not excluded.
3fill in blank
hard

Fix the error in this Rails API controller method to respond with JSON.

Ruby on Rails
def show
  user = User.find(params[:id])
  render [1]: user
end
Drag options to blanks, or click blank then click option'
Atext
Bhtml
Cxml
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using html renders a web page, not JSON data.
Using text or xml is not standard for Rails APIs.
4fill in blank
hard

Fill both blanks to configure middleware for a Rails API app.

Ruby on Rails
class Application < Rails::Application
  config.api_only = [1]
  config.middleware.use [2]
end
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
CActionDispatch::Cookies
DActionDispatch::Static
Attempts:
3 left
💡 Hint
Common Mistakes
Setting api_only to false disables API mode.
Adding Static middleware is for serving files, not cookies.
5fill in blank
hard

Fill all three blanks to create a simple JSON response in a Rails API controller.

Ruby on Rails
class GreetingsController < ApplicationController
  def hello
    message = { [1]: [2] }
    render [3]: message
  end
end
Drag options to blanks, or click blank then click option'
Agreeting
B"Hello, world!"
Cjson
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using text instead of json in render.
Forgetting to quote the string value.
Using an unrelated key name.