0
0
Ruby on Railsframework~10 mins

JSON rendering 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 render a JSON response with a message.

Ruby on Rails
render json: { message: [1] }
Drag options to blanks, or click blank then click option'
A"Hello, world!"
BHello, world!
C'Hello, world!'
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using single quotes instead of double quotes
2fill in blank
medium

Complete 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'
Auser.name
B"user.name"
C:user.name
Duser[:name]
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around user.name making it a string literal
Using symbol notation instead of variable
3fill in blank
hard

Fix 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'
Aitems.json
Bitems
C[items]
Ditems.to_json
Attempts:
3 left
💡 Hint
Common Mistakes
Calling to_json inside render json causing double encoding
Wrapping the array in brackets again
4fill in blank
hard

Fill 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'
Auser.id
Buser.email
C"user.email"
D"user.id"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around variables turning them into strings
Using string literals instead of variables
5fill in blank
hard

Fill 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'
Aproduct.name
Bproduct.price
Cproduct.available
D"product.name"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variables
Using string literals instead of variables