APIs on Rails revised in 2017 — Chapter 1
Book from 2014 by Abraham Kuri Vargas, revised in 2017
Chapter 1 - Introduction
I started doing “Apis On Rails” by Abraham Kuri (@kurenn). This is a book published in 2014 and today, as of this writing is august 2017. The app from the book is written in Ruby 2.1.2 and Rails 4.0.5 with RSpec 2.x. As suggested at the beginning I set up my environment by kaishi on my Ubuntu 16.04. kaishi has updated Rails for me to version 5.1.3. My Ruby version is 2.4.1, and later on you’ll see that I have (latest) RSpec 3.6 specified in Gemfile. Bear in mind that the goal of this post is to show only differences that has arose since 2014, rather than prescribing the whole book including these differences.
Little about the author
This is my first blog post ever. I am a self-taught developer. I code mostly in Ruby and Rails and have year and a half non-professional experience. I learn from books and open source and I never was on any paid bootcamp. English is not my native language. Please have this in mind while reading this post. Tweet me at @totenmilan if you feel the need.
1.2 Getting started
Separately from kaishi I have installed RailsAppsCustomGenerator but later I haven’t found any reference to it in the text while setting up new app, so I set up my app with
--no-rc flag to not use this generator.
rails new command uses this generator by default.
1.3.1 Installing Pow or Prax
I have skimmed the rest of installations in part 1.2, up to gem called prax. kaishi has installed it for me. prax wasn’t working at the beginning but rebooting the system helped. My default bash has changed to zsh by the way.
If you don’t want to use prax you can work this around by visiting lvh.me instead of localhost:3000, which can’t deal with subdomains. For more info check this Coderwall post. We will be specifying subdomains in chapter 2. After all I am using prax.
With prax and zsh in hand, I ran
$ rails server but got
zsh: command not found: rails. So I have googled “rails not found after installing zsh” and found this SO topic with the answer of @rodowi (rbenv case) linking to his article at Coderwall.
Now in zsh, prax is starting automatically. Worth noting is that I haven’t modified the .profile file, as book suggests. The domain market_place_api.dev:3000 is now working.
After googling a little about prax I found this Coderwall article. Now I don’t need to specify port after url, so it looks like this market_place_api.dev
1.3.2 Gemfile and Bundler
At this point I had some problems with zsh not recognizing presence of RSpec and bundler on my system (maybe more). For the command
$ rspec I got
zsh: command not found: rspec, same for bundler. Switching to bash and back again to zsh solved it for me.
You can switch to bash by executing in terminal
$ exec bash and go back to zsh by typing
$ exec zsh in the same terminal. If you’re not sure about something check this SO question about switching shells.
Because of some issues, I also need to update the rspec gem in my Gemfile (from 2.14 to 3.6) and it works fine.