I'm trying to build an Application that is using the OmniAuth gem, so that Twitter users can login.
I followed the steps in the tutorials and i'm pretty sure, that i've done everything right.
But on the callback from Twitter i get this infamous error message:
NoMethodError
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
After digging deeper in the omniauth gem, i figured out, that in the OAuth#callback_phase the session does not contain any oauth information
def callback_phase
::Rails.logger.info "session: #{session.inspect}"
::Rails.logger.info "consumer: #{consumer.inspect}"
request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
...
end
Log after callback
session: {"session_id"=>"190523311f7a63fe796558691b1d4fff"}
consumer: #<OAuth::Consumer:0x103735b50 #secret="...", #http=#<Net::HTTP api.twitter.com:443 open=false>, #key="...", #options={:access_token_path=>"/oauth/access_token", :proxy=>nil, :http_method=>:post, :site=>"https://api.twitter.com", :request_token_path=>"/oauth/request_token", :scheme=>:header, :oauth_version=>"1.0", :signature_method=>"HMAC-SHA1", :authorize_path=>"/oauth/authenticate"}>
So it looks like the Session content is not filled or gets lost on the way from twitter to omniauth.
Does anyone have a idea, what can cause the behavior?
My Gemfile:
gem 'mongrel', '1.2.0.pre2'
gem "rails", "~> 3.0.6"
gem "mysql"
gem 'omniauth'
gem 'settingslogic' # config/application.yml
gem 'will_paginate', '~> 3.0.beta'
Thanks for your help in advance.
In my session_store.rb I had something like this:
# Be sure to restart your server when you modify this file.
PersonalAccount::Application.config.session_store :cookie_store, :key => '_app_session', :secure => true
But in my development environment I did not use SSL, so OmniAuth could not store its session.
Removing the :secure => true resolved my problem.
Related
I'm running into this error after installing rails 5.0.0 on my project. I'm starting to think it's Devise gem or something. I tried multiple ways, but can't seem to figure it out.
I've tried this for devise gem, but same result.
gem 'devise', :github => 'plataformatec/devise', :branch => 'master'
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/nitrous/code/uvesty/config/environment.rb:5)
Exiting
/home/nitrous/code/uvesty/.bundle/gems/actionpack-5.0.0/lib/action_dispatch/middleware/stack.rb:108:in `assert_index': No such middleware to insert after: ActionDispatch::ParamsParser (RuntimeError
I also thought I might need to change all my
#user = User.find(params[:id])
to
#user = User.find_by(id: params[:id])
First change devise declaration in Gemfile like
gem "devise", '~> 4.0.0.rc1'
Secondly, you don't need to change this line, as find method is NOT deprecated.
#user = User.find(params[:id])
Please check what new in rails 5
The issue was the gem rails_admin. I removed it and it's all fine now. It seems they might have not updated their gem for rails 5.0.
I've been at this for awhile. I've tried using net http to connect to a https url with no luck. I've tried http party and getting uninitialized constant httpparty. I am running rails 3.2.7. I have httpparty add to gem file.
Can someone please provide an example with either problem sending params to a https url and receiving a response.
code:
options = {:id => params[:id], :code => params[:code]}
response = HTTPParty.post('https://test.com', options)
gem file:
gem "httparty", "~> 0.9.0"
HTTParty.get('https://google.com', :query => {:q => 'stack overflow'})
If this doesn't work for you, please show the code you're using. It you're getting an uninitialized constant error, you've done something wrong. Did you run bundle after adding to your Gemfile?
Also, it's HTTParty, not HTTPParty.
I'm using the google-api-client gem (gem google-api-client, '0.4.1' in my Gemfile). The following code caused the error uninitialized constant MyController::Google:
class MyController < ApplicationController
def index
#client = Google::APIClient.new
end
end
Specifying ::Google::APIClient didn't help, the error then said uninitialized constant Google.
Simply adding a require 'google/api_client' at the top of the file made this go away, so it seems there's something wrong in how auto-loading is being done. Not sure what's going on here exactly, specifying the gem in my Gemfile should have automatically required the gem, right? I have restarted the rails server btw.
Try adding a :require => 'google/api_client' where you specify the google api client gem in the Gemfile
gem 'google-api-client', :require => 'google/api_client'
This tells bundler that the correct way to require the gem 'google-api-client' is to require 'google/api_client'
Newly installed will_paginate 3.0.0
gem 'will_paginate', '~> 3.0.0', :require=>'will_paginate/data_mapper'
Running a controller query:
#tickets = Ticket.paginate(:page => params[:page], :per_page => 5,:username => #ticket.username)
Which works, pulls up all the tickets for a user and paginates in 5's if I put ?page=X where x is a page number in the url.
=will_paginate(#tickets)
in the view does not work, this results in
undefined method `will_paginate' for #<#<Class:0x000000053674c8>:0x0000000535cd48>
So will_paginate works, but not the view helper. Am I missing something? I'm using slim templating if that makes any difference. Is there some syntax change I'm missing? The documentation is simple but unhelpful beyond this point. I looked into the source, and there does not seem to be any changes, but I cannot figure why it is inaccessible
And then on tangent, this messes with an association.
=> #instance.model_belonging_to_instance.create(:text=>'test')
TypeError: can't convert nil into Integer
from /home/qx/.rvm/gems/ruby-1.9.2-p180/gems/will_paginate-3.0.0/lib/will_paginate/page_number.rb:16:in `Integer'
etc etc et al
SOLUTION:
gemfile:
gem 'will_paginate', '~> 3.0.0' # removed this, :require=>'will_paginate/data_mapper'
intializer:
require 'will_paginate'
require 'will_paginate/data_mapper'
It shows up, but if not at the top of the template, I get a
stack level too deep
error I am unable to interpret
Don't use the :require option in the Gemfile, as you already figured out; instead require "will_paginate/data_mapper" somewhere in config/application.rb, for instance after the Bundler setup.
There is a similar question with an answer that indicates that auto-requiring here is the problem. See will_paginate undefined method. The Will_paginate gem appears to work though for the question and answer.
gem 'will_paginate', '~> 3.0.0', require: %w[
will_paginate
will_paginate/data_mapper
]
for a new App I want to use paperclip to store Files to S3. I already have installed the aws-s3 gem for another app. That seems to cause some problems, because Paperclip should use right_aws but is trying to use the aws-s3 gem. But I don't want to remove the aws-s3 gem from my system. Is there a way to solve this conflict? Maybe by forcing paperclip to use right_aws? Or by changing the configuration?
My setup
# enviroment.rb
config.gem 'right_aws'
# my model with the attachment
has_attached_file :thumbnail,
:styles => { :thumb => "160x120>" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/amazons3.yml",
:path => ":provider/:attachment/:id_:style.:extension"
# config/amazons3.yml
development:
bucket: bucketname
access_key_id: secret
secret_access_key: secret
test:
bucket: bucketname
access_key_id: secret
secret_access_key: secret
production:
bucket: bucketname
access_key_id: secret
secret_access_key: secret
# The Error in the console
ArgumentError: wrong number of arguments (5 for 4)
from /Library/Ruby/Gems/1.8/gems/right_http_connection-1.2.4/lib/net_fix.rb:85:in `send_request_with_body_stream'
from /Library/Ruby/Gems/1.8/gems/right_http_connection-1.2.4/lib/net_fix.rb:85:in `exec'
from /Library/Ruby/Gems/1.8/gems/right_http_connection-1.2.4/lib/net_fix.rb:144:in `request'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/connection.rb:45:in `request'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/connection.rb:52:in `request'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:69:in `request'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `put'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:241:in `store'
...
Thanks!
Wow, that was fast. I solved the issue by just using the aws-s3 gem and therefore changing my enviroment.rb to read:
#config.gem 'right_aws'
config.gem "aws-s3", :version => ">= 0.6.2", :lib => "aws/s3"
Hope that helps somebody!
Not long ago Amazon released official AWS SDK for Ruby. It works pretty well with S3, supports American, European and Japanese S3 instances from the box and well maintained.
I have created a storage module for Paperclip called paperclip-aws to works with AWS SDK.
Feel free to use it. I hope that it will help.
I had this problem also. Specifying the gems in a certain order seems to work for some people:
config.gem "aws-s3", :lib => "aws/s3", :version => '>= 0.6.2'
config.gem "paperclip", :version => '>= 2.3.1.1'
# config.gem "right_aws"
In my app I also had a plugin (backup_fu) specifying right_aws as well, and I had to comment out the line in my plugin as well:
# backup_fu.rb
require 'yaml'
require 'active_support'
require 'mime/types'
require 'right_aws' unless defined?(RightAws)
require 'erb'
class BackupFuConfigError < StandardError; end
class S3ConnectError < StandardError; end
class BackupFu
# etc...
end
Does anyone know why this is an issue?
EDIT: In my app I no longer require right_aws at all, and then in the backup_fu gem I changed the require line to only require right_aws if it's not already loaded. I found that by requiring the gem in environment.rb, it caused a conflict with the aws-s3 gem. So now the backup_fu plugin will load it if required (usually only when running as a rake task), but not when the app is started up.
The main issue here is that aws-s3 redefines a method called send_request_with_body_stream.
aws-s3's version has 4 arguments, and right_http_connection's has 5. Depending on load order, aws-s3 can redefine right_http_connection's version of that method.
I cloned right_http_connection and made a quick fix for this issue. I sent a pull request to right_http_connection.
Therefore you can use my git repo in your bundle to fix this issue:
gem 'right_http_connection', :git => "git://github.com/gammons/right_http_connection"