0
0
Ruby on Railsframework~10 mins

API-only application setup in Ruby on Rails - Interactive Code Practice

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'
Aminimal
Bapi
Cfull
Dweb
Attempts:
3 left
💡 Hint
Common Mistakes
Using --full creates a full Rails app with views and assets.
Using --minimal is not a valid Rails new flag.
Using --web is not a recognized option.
2fill in blank
medium

Complete the code to generate a controller in an API-only Rails app.

Ruby on Rails
rails generate controller [1] --no-helper --no-assets
Drag options to blanks, or click blank then click option'
AHome
BAssets
CViews
DLayouts
Attempts:
3 left
💡 Hint
Common Mistakes
Generating controllers named 'Views' or 'Assets' which are not controllers.
Forgetting to skip helpers and assets in API apps.
3fill in blank
hard

Fix the error in the config to enable CORS in an API-only Rails app.

Ruby on Rails
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '[1]'
    resource '*', headers: :any, methods: [:get, :post, :options]
  end
end
Drag options to blanks, or click blank then click option'
Anil
Blocalhost
Cexample.com
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nil' causes errors.
Using 'localhost' restricts access to local only.
Using a domain without quotes causes syntax errors.
4fill in blank
hard

Fill both blanks to configure the API-only app to skip session and cookies middleware.

Ruby on Rails
config.api_only = true
config.middleware.delete [1]
config.middleware.delete [2]
Drag options to blanks, or click blank then click option'
AActionDispatch::Session::CookieStore
BActionDispatch::Cookies
CRack::Runtime
DActionDispatch::Flash
Attempts:
3 left
💡 Hint
Common Mistakes
Deleting unrelated middleware like Rack::Runtime.
Forgetting to delete cookies middleware.
5fill in blank
hard

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

Ruby on Rails
def index
  @items = Item.all
  render json: [1], status: [2], [3]: 'items'
end
Drag options to blanks, or click blank then click option'
A@items
B:ok
Croot
Ditems
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a variable for JSON data.
Using wrong status symbols.
Misnaming the root key option.