0
0
Ruby on Railsframework~10 mins

CORS configuration 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 allow all origins in CORS configuration.

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'
A"example.com"
B"localhost"
C"*"
D"https://myapp.com"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the origin string.
Using a specific domain when the task asks for all origins.
2fill in blank
medium

Complete the code to allow only 'https://example.com' origin in CORS configuration.

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'
A"https://example.com"
B"https://myapp.com"
C"http://localhost:3000"
D"*"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wildcard * instead of specific origin.
Omitting the protocol in the origin string.
3fill in blank
hard

Fix the error in the CORS configuration to allow GET and POST methods.

Ruby on Rails
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins "*"
    resource '*', headers: :any, methods: [1]
  end
end
Drag options to blanks, or click blank then click option'
A[:get, :post, :delete]
B[:post, :put]
C[:get]
D[:get, :post]
Attempts:
3 left
💡 Hint
Common Mistakes
Including extra HTTP methods not requested.
Using strings instead of symbols for methods.
4fill in blank
hard

Fill both blanks to allow only 'https://app.com' origin and enable GET, POST, and OPTIONS methods.

Ruby on Rails
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins [1]
    resource '*', headers: :any, methods: [2]
  end
end
Drag options to blanks, or click blank then click option'
A"https://app.com"
B[:get, :post, :options]
C[:get, :post]
D"*"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wildcard * for origins when a specific domain is required.
Omitting :options method.
5fill in blank
hard

Fill all three blanks to allow origins 'https://site1.com' and 'https://site2.com', enable GET and POST methods, and allow any headers.

Ruby on Rails
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins [1]
    resource '*', headers: [2], methods: [3]
  end
end
Drag options to blanks, or click blank then click option'
A"https://site1.com", "https://site2.com"
B:any
C[:get, :post]
D"*"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string with spaces instead of comma-separated origins.
Using string '*' for headers instead of symbol :any.