Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Accessing APIs with Ruby?

I'm building a Rails app that utilizes an API from another application, does anyone know any good resources on how best to do this in Ruby? I've only done it in Javascript before using AJAX... Thanks!

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hey there! There are a few ways to create a Rails API application. You can use this command to generate an API in rails:

# in rails 5.0 or above

rails new my_project --api 

--api flag tells Rails to generate an API application for ya. In turn, Rails strips off few gems like "sass-rails", "coffee-rails", "turbolinks", and few gems associated with your model 'coz its an API application that responds with XML and jSON . right? There is so much more to it which i cant explain here, but go through this great article right here.

There is an another way to achieve this. Since you're familiar with AJAX calls, you could do the same with Rails as well by integrating AJAX with your Rails application. As a Rails developer i've never integrated AJAX with Rails but there are few great blog posts out there. Check out here.

~ Ari