DEV Community

Cover image for Get up and running with Rails and Travis CI
Montana Mendy for Travis CI

Posted on • Updated on

Get up and running with Rails and Travis CI

Ruby on Rails, or just Rails, is one of the most popular model-view-controller frameworks in use on the web today. Developed in 2005 by David Heinemeier Hansson (co-founder of Basecamp), it set the precedent for a number of features found in most other MVC frameworks, such as database table creating and view scaffolding, allowing apps to be rapidly created from the structure of the database.

Rails works amazingly with Travis CI, so let's get you building even faster!

Let's put Travis on Rails!

You'll obviously want to signup for Travis, be sure to sync your account, open your Gemfile and add:

gem 'travis' 
Enter fullscreen mode Exit fullscreen mode

Run any migrations you may need to make, then:

bundle install
Enter fullscreen mode Exit fullscreen mode

In this use case, we are creating the .travis.yml via:

travis init
Enter fullscreen mode Exit fullscreen mode

You don't in theory need to specify a Ruby version, Travis will look at your ruby-, but you can definitely specify a Ruby version if you chose to:


language: ruby
dist: xenial
rvm: 2.5.8
Enter fullscreen mode Exit fullscreen mode

That tells Travis what language (Ruby), what dist you'll be using (also can be changed) and rvm the version of Ruby you'll be using. You can now add script which is commands you're telling Travis to run when you triggered a build, so it could look like the following:

script:
 — bundle install — jobs=3 — retry=3
 — bundle exec rake db:create
 — bundle exec rake db:migrate
 — bundle exec rspec
Enter fullscreen mode Exit fullscreen mode

You can then check your .travis.yml's validity via the linting online application Travis Lint, or do it manually:

 travis lint
Enter fullscreen mode Exit fullscreen mode

Then commit changes and see your Rails app build! We push to GitHub, we'll be doing this in a variety of different ways in the upcoming Cookbook entries, so you'll have a choice on how you'd like to deploy!


 git init
 git add . 
 git commit -m "Travis build" 
 git remote add origin remote repository URL
 git remote -v 
 git push -u origin master
Enter fullscreen mode Exit fullscreen mode

That's it, you're setup. Travis is on Rails. We have new recipes every other week, so make sure you come back next week for a practical way of using Travis CI!

Originally posted on the Travis CI blog

Top comments (2)

Collapse
 
bsgreenb profile image
Ben Greenberg 🧢 • Edited

We're considering using TravisCI for our Contentful migration CI. Looks like it's pretty easy to setup!

Collapse
 
montana profile image
Montana Mendy • Edited

Glad my tutorial was easy for you! When you do go with Travis CI be sure to contact me personally and I will help you, or there's a great community forums over at travis-ci.community/