omniauth w/ Twitter not working on rails 3.1.0.rc5 - ruby-on-rails-3

I have a Rails app running on 3.1.0.rc5, and I've setup omniauth for twitter exactly the same as seen here (https://github.com/sferik/sign-in-with-twitter) but it's still not working.
The problem is that after Twitter is redirecting back to my callback URL I have request.env["omniauth.auth"] is nil, rack.auth is nil too. I even went so far as to print out the entire request.env hash and didn't see anything like access_token or access_secret.
The only thing that doesn't look like my request token and secret is stored in action_dispatch.secret_token.
Any ideas on how to make this work?

Ok, so I got this working now. My Gemfile was:
gem "oa-oauth", :require => "omniauth/oauth"
gem "twitter"
I changed it to:
gem 'omniauth', :git => 'git://github.com/intridea/omniauth.git'
gem 'twitter'
gem 'json_pure'
gem 'json'
And everything started working. The request.env["omniauth.auth"] key was present etc. I had to add the json gem lines because of a uninitialized constant JSON::ParserError error I was getting. I think that is a bug in the release candidate.

Related

Rails 4.0 & Devise - Strong Parameters error

Newbie to rails here, so bear with me.
New app on Rails 4 with ruby 2.0, I installed Devise and followed the instructions(default root, etc). Devise readme on github says it should be compatible with rails4 but
db:migrate failed unless I commented out attr_accessible line in User.rb
After commenting that out, I get "ActiveModel::ForbiddenAttributesError in Devise::RegistrationsController#create" error in trying to create a user.
I see some stack overflow questions like this, but a lot of the answers jump straight into some complex talk. I get I need to specify permitted attributes for mass assignment, but how? And where? And which attributes need to be permitted, all of them? Only those that I expect to be changed/created at the same time?
Judging by the error would I create a registrations_controller.rb that inherits from Devise::registrationsController ? What do I specify in that?
Any step by step, newbie friendly answers are much appreciated. I've exhausted myself trying different code from answers here and various sites from google searches.
Welcome to stackoverflow!
The problem is that the functinality of attr_accessible changed in rails 4.0
2 possibilities to get it running
1 Update Devise that it can handle Rails 4.0
Add this line to your application's Gemfile:
gem 'devise', '3.0.0.rc'
And then execute:
$ bundle
2 Add the old functionality of attr_accessible again to rails 4.0
Try to use attr_accessible and dont comment this out.
Add this line to your application's Gemfile:
gem 'protected_attributes'
And then execute:
$ bundle
Adding below gems and doing a bundle install worked for me
source 'https://rubygems.org'
gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.3.2.0'
gem 'devise', '3.0.0.rc'
gem 'protected_attributes'
gem 'sqlite3'

no such file to load -- google_chart using gem gchartrb

I am trying to use the gem gchartrb to create some graphs/charts in my RoR application.
I have looked into several tutorial and all say the same thing, that I have to add
require 'google_chart'
But I am getting the message:
no such file to load -- google_chart
I have the require inside my controller, I have confirmed that the gem is installed.
I am using Rails 3.
Also, I have tried adding config.gem 'gchartrb', :lib => 'google_chart' in my environment.rb as suggested here but nothing changed
Thanks for your help
EDIT:
I have also tried with the gem googlecharts, what I have in my Gemfile is:
gem "googlecharts", :require => "gchart"
but I get no such file to load -- gchart when I try to load the view.
I am not sure, it is required now or not. But it worked for me in Rails 3 as well. I am using Rails 3.0.10. I added below 2 lines and it worked for me.
1) gem 'gchartrb' in Gemfile
2) require 'google_chart' in config/boot.rb
Hope it helps!
config.gem is for rails 2.3.X.
For rails 3, you will need to add the gem to your Gemfile and run gem bundle
You may also need to check that the google_charts gem actually supports Rails 3...
Given that the latest code update seems to have been in 2008 - that might not actually be likely. :(
You can try it anyway and see...

OmniAuth Invalid Response - Updating to 1.9.2 not working

Hi
I know this question have been asked before but the answers there isn't working for me.
I still get the, when redirecting back to my site.
/auth/failure?message=invalid_response
I have ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0] installed, using rails 3.0.7 and the required gems installed. I read on another thread that you should have pure_json added to the gemfile to make it work. But that didn't help me either.
I'm clueless... Thanks in advance
authenticationscontroller
def index
#authentications = current_user.authentications if current_user
end
def create
#render :text => request.env["omniauth.auth"].to_yaml
auth = request.env["omniauth.auth"]
current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
I was able to get this to work by specifying the following in my Gemfile
gem 'omniauth', '0.2.0'
Version 0.2.6 wouldn't work for me. I also updated by .rvmrc to rvm use 1.9.2#rails3. Oh, also make sure you're logged in - do note that in your code above you are assuming that current_user exists. See Ryan's Railscast part two for allowing user creation via Omniauth.
I've got a demo working here, but do note I'm doing authentication from scratch rather than using Devise.

Rails 3 + FactoryGirl: NameError: uninitialized constant Factory

ruby-1.9.2-p180 :007 > Factory.define :user do |user|
ruby-1.9.2-p180 :008 > user.email "user#example.com"
ruby-1.9.2-p180 :009?> user.password "foobar"
ruby-1.9.2-p180 :010?> user.password_confirmation "foobar"
ruby-1.9.2-p180 :011?> end
NameError: uninitialized constant Factory
My Gemfile:
group :test do
gem "rspec-rails"
gem 'webrat', '0.7.1'
gem 'spork', '0.9.0.rc4'
gem 'factory_girl_rails'
end
Even tough it seems I have everything as it should, I keep getting that error. I also have factories.rb created.
Thanks
I suppose you try in console in development environment. But you add the Factory gem only in test environment.
If you want access to Factory_girl in development use in your Gemfile :
group :test, :development do
gem 'factory_girl_rails'
end
Or if you want test your Factory launch your console in test environment :
rails c test
We had a similar problem on our end, rake spec seemed to be randomly failing with the error uninitialized constant FactoryGirl. The error was random -> coming and going. We went back half a dozen git commits to try and resolve it. In the end it was a silly mistake.
The fundamental problem is RAILS_ENV is set to development. It needs to be set to test when you run rake spec.
Address by:
Making certain that we are running rake spec in the RAILS_ENV test environment and its exported/sourced properly. To never confuse our environemnts, we modified zsh $RPROMPT env variable to show the current env.
export RPROMPT="[%{$fg_no_bold[yellow]%}$RAILS_ENV%{$reset_color%}]"
Require FactoryGirl in the spec ruby files gave a much better error message. At least rspec would run vs just fail outright this way when the environment was wrong. We also updated our gemfile to make sure factory_girl_rails and factory_girl were loaded both for development and testing.
Now we just run rpsec using the gem guard in a dedicated terminal with the proper RAILS_ENV set.
Its one of those gotchas.
We're running Ruby 1.9.3, Rails 3.2.9, Rspec 2.12, factory_girl 4.1.
I also ran into this while I was doing the Hartl tutorial.
If you are using "Spork" to speed up your tests and it is running in the background when you add the FactoryGirl code, you will need to stop it and restart it.
You should also change Factory.define to FactoryGirl.define, like in this example
FactoryGirl.define do
factory :user do
name 'John Doe'
date_of_birth { 21.years.ago }
end
end
from the factory_girl documentation

Webmock gem in rails 3 and properly including it

I'm likely doing something very simply wrong, but I'm not quite sure what it is. I am porting a rails 2 application to rails 3. This application uses webmock for a bunch of it's tests.
If I include
gem 'webmock'
In my Gemfile, the tests pass, but when I start the server and run the app locally, hitting a controller that should make a web call throws an error:
WebMock::NetConnectNotAllowedError
If I do NOT include the line in my Gemfile, then when I run the app locally, it works fine, but the tests error out with:
`require': no such file to load -- webmock (LoadError)
When this line is hit in my test_helper.rb
require 'webmock'
I'm guessing I've got something configured wrong, but I haven't hit the right google incantation to shed any light on it yet. Where I did I go astray?
Thank you.
Try telling your Gemfile to only load webmock when you're in a test environment:
group :test do
gem "webmock"
end
On my Ruby 1.9 Rails 3 instance I have something like the following:
group :test do
gem "mocha"
gem "webmock"
end
group :development do
gem 'ruby-debug19', :require => 'ruby-debug'
end