> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bundleup.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Rails Quickstart

> Connect your first integration with a Ruby on Rails app using BundleUp.

Get started with BundleUp in a Rails application. This guide walks you through creating an authorization flow to connect a third-party service (**GitHub** in this example) and then uses that connection to fetch API data via BundleUp's unified API.

By the end of this guide, you'll:

* Redirect a user through an OAuth-style authorization flow
* Receive a `connection_id`
* Use that `connection_id` server-side with the Ruby SDK to fetch data

## Prerequisites

Before you begin, make sure you have:

* A [BundleUp account](https://www.bundleup.io)
* A BundleUp **API key** (server-side)
* Your BundleUp **Client ID** (used for authorization redirects)
* An **Integration ID** for the service you want to connect (for example, `github`)
* Ruby 2.7+ and Rails installed

<Info>
  You can find your API key, Client ID, and Integration IDs in the BundleUp dashboard.
</Info>

## Step 1: Create a new Rails app

Create a fresh Rails project:

```shellscript theme={null}
# using Rails CLI
rails new bundleup_rails
cd bundleup_rails

# ensure the app’s database is ready
rails db:create
```

This scaffolds a Rails app you can run locally.

## Step 2: Install the BundleUp Ruby SDK

Add the `bundleup-sdk` gem to your Gemfile:

```ruby theme={null}
# Gemfile
gem 'bundleup-sdk'
```

Then install dependencies:

```shellscript theme={null}
bundle install
```

This makes the BundleUp client available to your Rails app.

## Step 3: Configure environment variables

Create a `.env` file (or use your preferred secrets manager) with:

```shellscript .env lines theme={null}
# server-side only
BUNDLEUP_API_KEY=your_api_key_here

# used for redirect
BUNDLEUP_CLIENT_ID=your_client_id_here
BUNDLEUP_INTEGRATION_ID=github
BUNDLEUP_REDIRECT_URI=http://localhost:3000/callback
```

Make sure your Rails app loads these variables (for example via [dotenv-rails](https://rubygems.org/gems/dotenv-rails) or [Rails credentials](https://edgeguides.rubyonrails.org/security.html#environmental-security)).

## Step 4: Add routes

In `config/routes.rb`, define the home and callback endpoints:

```ruby config/routes.rb lines theme={null}
Rails.application.routes.draw do
  root "home#index"
  get "/callback", to: "home#callback"
end
```

## Step 5: Create the authorization link

In `app/controllers/home_controller.rb`, add:

```ruby app/controllers/home_controller.rb lines theme={null}
class HomeController < ApplicationController
  def index
    client_id = ENV["BUNDLEUP_CLIENT_ID"]
    integration_id = ENV["BUNDLEUP_INTEGRATION_ID"]
    redirect_uri = ENV["BUNDLEUP_REDIRECT_URI"]

    @auth_url = [
      "https://auth.bundleup.io/authorize?",
      "client_id=#{client_id}",
      "integration_id=#{integration_id}",
      "redirect_uri=#{redirect_uri}"
    ].join("&")
  end

  def callback
    @error = params[:error]
    @error_description = params[:error_description]
    @connection_id = params[:connection_id]
  end
end
```

Then create simple views.

```ruby app/views/home/index.html.erb lines theme={null}
<%= link_to "Connect GitHub", @auth_url %>
```

This link sends the user to BundleUp’s auth server to authorize the integration.

## Step 6: Handle the callback and fetch data

Update `callback` action in `HomeController`:

```ruby app/controllers/home_controller.rb lines theme={null}
require "bundleup-sdk"

class HomeController < ApplicationController
  def callback
    if params[:error]
      @error = params[:error_description]
      return
    end

    connection_id = params[:connection_id]
    client = BundleUp::Client.new(api_key: ENV["BUNDLEUP_API_KEY"])

    # example: fetch GitHub repos
    @repos = client.unify(connection_id).git.repos.data
  end
end
```

Then update `app/views/home/callback.html.erb`:

```ruby app/views/home/callback.html.erb lines theme={null}
<% if @error %>
  <p>Error: <%= @error %></p>
<% else %>
  <h2>Repositories</h2>
  <ul>
    <% @repos.each do |repo| %>
      <li><%= repo["full_name"] %></li>
    <% end %>
  </ul>
<% end %>
```

Now, after a successful authorization redirect, you use the `connection_id` to fetch a unified API resource using the Ruby SDK.

## Step 7: Run your application

Start the Rails server:

```shellscript theme={null}
rails server
```

Visit [http://localhost:3000](http://localhost:3000), click **Connect GitHub**, authorize the app, and then you’ll see data fetched through BundleUp.

## What’s next?

* Persist `connection_id` to your database for later use
* Add authenticated views that use the Ruby SDK to fetch user data
* Support additional integrations with no auth changes
