twitter gem not working in heroku? - ruby

I'm working on a ruby app that updates a twitter account using 'twitter' gem. It's working fine locally (as usual :) ). But when I deploy it on heroku it seems the gem is not properly installed or something lile that as I got the following error:
NameError: uninitialized constant Twitter::OAuth
My code is very simple:
oauth = Twitter::OAuth.new(consumer_token, consumer_secret)
oauth.authorize_from_access(access_token, access_secret)
client = Twitter::Base.new(oauth)
client.update("Updating my status from twitter gem. GREAT!")
Is there a problem with this particular gem ?
Thanks a lot for your help.
Luc

Have you created a .gems file and put twitter in it?
Depending on which heroku 'stack' you are on, you may need to do that instead of a bundler Gemfile. You can change your stack for one that uses bundler by doing this:
heroku stack:migrate bamboo-ree-1.8.7
Which makes bundler available (I think).

That is a common message that usually implies that you have a discrepancy between your local gems and the gems in heroku. If you are not using Bundler yet, you should. You will end un writing a very simple Gemfile that will tell Heroku (or any other entity using your code) which gems and versions you require.
http://gembundler.com/

I would suggest that you should use the heroku addon called 'apigee', ut makes twitter on heroku simple:
http://addons.heroku.com/apigee

I just got a sinatra app talking to Twitter through Heroku/Apigee, my rate limit went from 300 calls per hour to 20,000 calls per hour. Here's a step by step on what to do:
http://geeks.aretotally.in/mind/2011/1/8/increasing-api-limits-on-a-sinatra-twitter-app-with-twitter_.html
I am really a Java developer just playing around with Sinatra but let me know if I can help in anything.
Felipe

Related

can't get ruby omniauth-ebay-oauth gem example code working

I am trying to setup and use omniauth-ebay-oauth (https://github.com/evilmartians/omniauth-ebay-oauth) gem to use eBay rest APIs in my app without success.
I set up the required environment variables and run the example code but get a message saying "Sinatra doesn’t know this ditty.". It does not recognise the '/auth/ebay' route, not sure if I have to declare that route myself nor what to put in it if I do. I'm new to ruby and Sinatra so do apologise if this is just something silly and obvious that I'm missing.
require 'omniauth-ebay-oauth'
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :ebay_oauth, ENV['EBAY_CLIENT_ID'], ENV['EBAY_CLIENT_SECRET'],
callback_url: ENV['EBAY_RU_NAME'], name: 'ebay'
end
get '/' do
redirect '/auth/ebay'
end
get '/auth/ebay/callback' do
"Hello, #{request.env['omniauth.auth'].dig('info', 'name')}"
end
I appreciate any help and insight in getting this working. I've googled everywhere and asking here as my last resort.
I opened an issue on the GitHub repository and the gem creator replied in 3 hours. Totally life saver. I will post the solution here to help others.
It is because of security settings of OmniAuth 2.x.
Add the following line at the top, after requires:
OmniAuth.config.allowed_request_methods += %i[get]
This worked like a charm and I can now move forwards with the project.

Getting Paperclip::AdapterRegistry::NoHandlerError when using Padrino

I've been getting an issue where when using Padrino and paperclip whenever I try to upload an image I get the error
Paperclip::AdapterRegistry::NoHandlerError
What's going wrong?
For those wondering, the multipart form thing mentioned in many other posts is also true. See Other SO posts
All of those relate to Rails and specifically if you are using Padrino or another rack based application, you need to add one more thing or else it won't work
The exception being thrown was due to the uploaded file being represented by a Hash (Rack converts it into a Hash), and that Paperclip does not provide an adapter for this Rack specific Hash out of the box.
You need to install this gem:
gem 'paperclip-rack', require: 'paperclip/rack'

Did rails 5 drop it's support for rest client gem?

Today when I tried to use the RestClient in my freshly installed rails project I got an err. Then I thought I had to import it so I did require 'rest-client' and also got an err. But when I installed it in my gem file and then the problem resolved.
There is no support for rest client gem in the Rails. You can check the Gemfile. I assume you are talking about the Ruby gem, if so, you can find all related information in the documentation for rest-client gem.

Rails 4 - ActiveAdmin - Redactor - Heroku -- has no method 'redactor' console error

I've been trying to tackle this all morning. Locally, this setup works just fine. I am not using the redactor-rails gem because this is a rails 4 app and it doesn't support it. I have moved the redactor.css and redactor.js calls from the active_admin initializer file to be required in my actice_admin.js.coffee and active_admin.css files because on Heroku, it could not find the path. Now, when firing up the page that should be displaying redactor, I get has no method 'redactor' in the console.
I'm at a loss. I've read up on precompiling assets and the how the pipeline works, but it doesn't seem like I'm doing anything out of the ordinary here.
So how can I deploy to Heroku without this error?
Ok, so I seemed to have disregarded an important task. After thinking about precompilation a bit more I remembered I had been told to run
RAILS_ENV=production bundle exec rake assets:precompile
before. After running that again, it precompiled the active_admin.css and active_admin.js.coffee files which had the new require's in it. Viola!
Hope this helps someone else in the future.

MongoMapper in a custom gem with rspec

Hopefully I'm just missing something simple. I am using mongomapper in a rails 3 app and it works beautifully. I needed to share it with another app and pushed it out to a gem, which also works great from both rails apps. However, when I try to add rspec tests to the gem I am getting the following error:
/Users/dane/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant User::MongoMapper (NameError)
I am adding a really simple test for my User model.
Thanks!

Resources