This guide will walk you through your first steps using Contentful within a Rails application. It will provide a step-by-step guide on how to get your first entries and start using the content you create on Contentful.
First we'll start with a demo project, which is a simple Rails application using Contentful's 'Product Catalogue' template, so that you can see it running for yourself.
Run the following commands to get started.
git clone https://github.com/contentful/contentful_rails_tutorial.git
bundle exec rake db:create db:migrate db:seed
bundle exec rails s
Everything is now set up. You can view your new data by opening http://localhost:3000/contentful_users/1 in your browser.
It should look something like this:
You can create your own custom data by following these steps:
Next in the Contentful web app > Content:
You can continue to edit your content inside the Contentful web app and see the content change inside your Rails application.
To view the demo application live in your own production environment, follow these steps:
heroku addons:create heroku-postgresql:hobby-dev
VALUE_OBTAINED_FROM_YOUR_HEROKU_PG_CONFIG with the database name in your Heroku Database's Dashboard. You can find the name at Heroku Database Dashboard > Your Postgres instance > Database.
git add . git commit -m "Update Database Configuration"
git push heroku master
heroku run env bundle exec rake db:migrate db:seed
After this guide, you should be able to start using Contentful with your Rails applications, but every project has different needs and we want to provide you with the best solutions we can.
You can read about the Contentful CDA library in more detail on our contentful.rb GitHub or our Getting Started with CDA SDK tutorial, we also suggest taking a look at our Contentful Rails Example Application.
If you want to create your own Rails project we recommend following this tutorial, or our Rails integration libraries
contentful_rails, which provide a more Rails-like approach to creating Contentful based applications.
If you want to set up new spaces via the command line we also provide Contentful Bootstrap.