Mike Coutermarsh
  • Home
  • About
  • Twitter
  • GitHub
Sign in Subscribe

Grape/Rails API Cross-Origin Resource Sharing

  • Mike Coutermarsh

Mike Coutermarsh

Dec 16, 2012

If you want to allow access to your Grape API from other domains, you need to implement CORS!

It’s easy with the rack-cors gem. Here’s how you do it.

Add rack-cors to your gemfile.

gem 'rack-cors', :require => 'rack/cors'

Then go to your application.rb and add:

[gist id="4297940"]https://gist.github.com/4297940

done!

Get notified of new posts

Enter your email
Subscribe

New Rails health check endpoint

Rails just recently added a default /up route that will return a 200 when the application is running. I've had to implement this in pretty much every Rails app I've ever worked on. This is a nice addition! If you're not familiar. This is useful for load balancers which need
Jan 13, 2023 1 min read

Solving N+1’s with Rails `exists?` queries

I recently solved a Rails performance issue with exists? queries in our Rails API. Shared all the details on PlanetScale's blog. Check it out here: Solving N+1's with Rails exists queries.
Jan 10, 2023

Searching complex Rails routes

Mastering the routes command will save you a lot of time. Here are a pro tips on how to use it. rails routes Prefix Verb URI Pattern Controller#Action new_user_session GET /sign-in(.:format) users/sessions#new {:subdomain=>"auth"} user_session POST /sign-in(.:format)
Jan 7, 2023 1 min read
Mike Coutermarsh © 2023
  • HTML/CSS to Image API
  • Twitter
  • GitHub
  • LinkedIn