Ruby on Rails 5 API

After using Ruby on Rails 5 I do not want to go back, I’ve fell in love. In my opinion this was one of the best updates in software. My congratulations to the core team and all the contributors.

Bcrypt gem is included and it is not necessary the old manual configuration steps which spares a lot of time and makes us focused on other important things.

In some commands the old rake is gone, such as:

rails db:migrate
rails test

To build the API:

rails new tasks --api

Then you add this code to the Gemfile

gem 'active_model_serializers'

After, you create this file and write the code that follows

config/initializers/active_model_serializers.rb

ActiveModel::Serializer.config.adapter = :json_api

Run this command to update the gems

bundle install

Create both Users and Todos using scaffold

rails generate scaffold User email
rails g scaffold Todo title completed:boolean order:integer category:string user:references

The scaffold option makes a lot of things for us but there is more work to do, some configuration, more code and in my case I added authentication.

The code can be checked in my github through the following link: https://github.com/Adnilson/tasks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s