Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to render a JSON response with a message.
Ruby on Rails
render json: { message: [1] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using single quotes instead of double quotes
✗ Incorrect
The message value must be a string in quotes to render valid JSON.
2fill in blank
mediumComplete the code to render a JSON object with a user's name.
Ruby on Rails
render json: { user: { name: [1] } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around user.name making it a string literal
Using symbol notation instead of variable
✗ Incorrect
Use the variable user.name to get the name value for JSON rendering.
3fill in blank
hardFix the error in rendering JSON with an array of items.
Ruby on Rails
render json: { items: [1] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling to_json inside render json causing double encoding
Wrapping the array in brackets again
✗ Incorrect
Rails automatically converts arrays to JSON, so just pass the array variable.
4fill in blank
hardFill both blanks to render JSON with a user's id and email.
Ruby on Rails
render json: { id: [1], email: [2] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around variables turning them into strings
Using string literals instead of variables
✗ Incorrect
Use user.id and user.email variables without quotes to render correct JSON values.
5fill in blank
hardFill all three blanks to render JSON with a product's name, price, and availability.
Ruby on Rails
render json: { name: [1], price: [2], available: [3] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variables
Using string literals instead of variables
✗ Incorrect
Use product's attributes directly without quotes to render JSON correctly.