Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:43:22+00:00 2026-06-13T22:43:22+00:00

I am playing with the heroku api in Rails and have come across a

  • 0

I am playing with the heroku api in Rails and have come across a potential issue.

After submitting a login form i am instantiating the heroku object.

heroku = Heroku::API.new(:username => USERNAME, :password => PASSWORD)

I would then like to use the heroku object in all controllers to further querying the api. I have tried @heroku, @@heroku and $heroku, but none work. Is this possible?

The only solution i have found it to use the api to fetch the users api key, store this in a session then use it to re-instantiate the heroku object within each controller method. Is this the best / only solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:43:24+00:00Added an answer on June 13, 2026 at 10:43 pm

    In general, a before_filter could solve your re-instantiating problem. If you want to set an instance variable that is available to every controller method, do something like this:

    class UsersController < ApplicationController
    
      before_filter :get_user
    
      def profile
        # @user is accessible here
      end
    
      def account
        # @user is accessible here
      end
    
      private 
    
      def get_user
        @user = User.find(params[:id])
      end
    
    end
    

    You can also user before_filters in the application controller to set instance variables that are accessible in all of your controllers. Read about filters here.

    As for storing the API keys to the session, that works, but if you want long term access, you might want to write the API keys to the database. Combined with before filters, you could do something like this:

    class ApplicationController < ActionController::Base
    
      before_filter :setup_heroku
    
      def setup_heroku
        if current_user && current_user.heroku_api_key
          @heroku = Heroku::API.new(:api_key => current_user.heroku_api_key)
        end
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Playing around with a custom built CMS and I have an issue where I
I have been playing around with different caching strategies on Heroku and have add
Playing a little with coffeescript and Rails 3.1.0.rc4. Have this code: yourMom = (location)
Just playing around with Wordpress / Contact Form 7 . Is it possible to
Am playing with Google Maps V3 API and StyledMarkers. The data is derived from
Playing with breezejs. Here is a code: var dataService = new breeze.DataService({ serviceName: /api/articles,
Playing with css border, margin, padding and width I came across an extra pixel...
playing around with a new samsung tablet i noticed they have mini apps on
Playing a video to start the application I have this code, I can't see
Playing around with the Web API with Framework 4.0 Wanted XML only output, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.