Rails, Omniauth, Authlogic, and Facebook - first step - ruby-on-rails

I'm trying to get Facebook logins working on my app using Rails, Authlogic, and Omniauth. I'm following the first steps of http://railscasts.com/episodes/235-omniauth-part-1 as precisely as possible.
I have:
added the omniauth gem, run bundle install.
created a new Authentication nifty-scaffold with fields user_id, provider, and uid.
added the route: match '/auth/:provider/callback' => 'authentications#create'
added to config/initializers/omniauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '20...my_app_id', 'bc...my_app_secret'
end
The server then fails to restart:
/Users/san/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:
in 'const_missing_from_s3_library': uninitialized constant
OmniAuth::Strategies::Facebook (NameError)
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in 'const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/omniauth-1.0.0/lib/omniauth/builder.rb:22:in 'const_get'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/omniauth-1.0.0/lib/omniauth/builder.rb:22:in 'provider'
from /Users/san/Documents/sanj/myapp/config/initializers/omniauth.rb:2:in 'block in <top (required)>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/builder.rb:46:in 'instance_eval'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/builder.rb:46:in 'initialize'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/omniauth-1.0.0/lib/omniauth/builder.rb:7:in 'initialize'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/stack.rb:33:in 'new'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/stack.rb:33:in 'build'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/stack.rb:79:in 'block in build'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/stack.rb:79:in 'each'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/stack.rb:79:in 'inject'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/stack.rb:79:in 'build'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/application.rb:162:in 'app'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/application/finisher.rb:35:in 'block in <module:Finisher>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/initializable.rb:25:in 'instance_exec'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/initializable.rb:25:in 'run'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/initializable.rb:50:in 'block in run_initializers'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/initializable.rb:49:in 'each'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/initializable.rb:49:in 'run_initializers'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/application.rb:134:in 'initialize!'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/application.rb:77:in 'method_missing'
from /Users/san/Documents/sanj/myapp/config/environment.rb:5:in '<top (required)>'
from /Users/san/Documents/sanj/myapp/config.ru:3:in 'block in <main>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/builder.rb:46:in 'instance_eval'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/builder.rb:46:in 'initialize'
from /Users/san/Documents/sanj/myapp/config.ru:1:in 'new'
from /Users/san/Documents/sanj/myapp/config.ru:1:in '<main>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/builder.rb:35:in 'eval'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/builder.rb:35:in 'parse_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/server.rb:162:in 'app'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/server.rb:253:in 'wrapped_app'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.3/lib/rack/server.rb:204:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/commands/server.rb:65:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/commands.rb:30:in 'block in <top (required)>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/commands.rb:27:in 'tap'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.10/lib/rails/commands.rb:27:in '<top (required)>'
from script/rails:7:in 'require'
from script/rails:7:in '<main>'

I had to do 'require "omniauth"' or 'require "omniauth-facebook"' in my config/development.rb file.

The omniauth gem was just bumped to version 1.0 as of yesterday (http://intridea.com/2011/11/2/omniauth-1-0), and there are some changes to how the gem is used that are not covered in the railscast.
I found my solution on this page: https://github.com/intridea/omniauth/wiki/OmniAuth-1.0
The biggest different is that each strategy is now contained within its own gem, so for facebook, you would change the line in your gem file that currently reads "gem 'omniauth'" to "gem 'omniauth-facebook'".
I didn't have to change any other code, and you may have to run "bundle update" to get everything to click through.

I just ran into this problem and this is what was wrong with me:
You can't have your facebook oauth gem in the Development list in your gem file. Heroku only reads the Production ones, so move it up out of the Development list.

Related

when running $ rails test, get the result as below

when running $ rails test, I get the error as below, how to solve this problem?
/home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/testing/declarative.rb:14:in 'test': test_should_get_help is already defined in StaticPagesControllerTest (RuntimeError)
from /home/nafihnafi/workspace/sample_app/test/controllers/static_pages_controller_test.rb:10:in '<class:StaticPagesControllerTest>'
from /home/nafihnafi/workspace/sample_app/test/controllers/static_pages_controller_test.rb:3:in '<top (required)>'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in 'require'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in 'block in require'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:in 'load_dependency'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in 'require'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:14:in 'block in require_files'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:13:in 'each'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:13:in 'require_files'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/minitest_plugin.rb:94:in 'plugin_rails_init'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:81:in 'block in init_plugins'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:79:in 'each'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:79:in 'init_plugins'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:130:in 'run'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.1.1/lib/rails/test_unit/minitest_plugin.rb:77:in 'run'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:63:in 'block in autorun'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
from /home/nafihnafi/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
from -e:1:in '<main>'
You're defining test_should_get_help somewhere again, when it's already been defined. Make sure it's only defined once - put the function in a private block at the end of the file like this:
[file end]
private
def test_should_get_help
[blah]
end
If you need it in multiple files, try adding it as a helper.

Devise issue while starting rails app in production mode

I have a rails app on my server which runs perfectly when I do rails s -b domain.name but when I run rails s -b domain.name -e production or RAILS_ENV=production rails s -b domain.name I have this following error.
=> Booting Puma
=> Rails 4.2.6 application starting in production on http://domain.name:3000
=> Run 'rails server -h' for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:244:in 'rescue in load_dependency': /home/deploy/appname/app/controllers/users/confirmations_controller.rb:2: unknown regexp options - cfrat (SyntaxError)
/home/deploy/appname/app/controllers/users/confirmations_controller.rb:7: unknown regexp options - cfrat
/home/deploy/appname/app/controllers/users/confirmations_controller.rb:12: unknown regexp options - cfrat
/home/deploy/appname/app/controllers/users/confirmations_controller.rb:13: syntax error, unexpected keyword_def, expecting ':'
def show
^
/home/deploy/appname/app/controllers/users/confirmations_controller.rb:27: syntax error, unexpected keyword_end, expecting end-of-input
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:237:in 'load_dependency'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in 'require'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:360:in 'require_or_load'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:317:in 'depend_on'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:233:in 'require_dependency'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:472:in 'block (2 levels) in eager_load!'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:471:in 'each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:471:in 'block in eager_load!'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:469:in 'each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:469:in 'eager_load!'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/engine.rb:346:in 'eager_load!'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/application/finisher.rb:56:in 'each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/application/finisher.rb:56:in 'block in <module:Finisher>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in 'instance_exec'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in 'run'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in 'block in run_initializers'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:228:in 'block in tsort_each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:350:in 'block (2 levels) in each_strongly_connected_component'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:431:in 'each_strongly_connected_component_from'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:349:in 'block in each_strongly_connected_component'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:347:in 'each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:347:in 'call'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:347:in 'each_strongly_connected_component'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:226:in 'tsort_each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tsort.rb:205:in 'tsort_each'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in 'run_initializers'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/application.rb:352:in 'initialize!'
from /home/deploy/appname/config/environment.rb:5:in '<top (required)>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in 'require'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in 'block in require'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in 'load_dependency'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in 'require'
from /home/deploy/appname/config.ru:3:in 'block in <main>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in 'instance_eval'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in 'initialize'
from /home/deploy/appname/config.ru:in 'new'
from /home/deploy/appname/config.ru:in '<main>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in 'eval'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in 'new_from_string'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in 'parse_file'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:299:in 'build_app_and_options_from_config'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:208:in 'app'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:61:in 'app'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:336:in 'wrapped_app'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:272:in 'start'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:80:in 'start'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in 'block in server'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in 'tap'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in 'server'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in 'run_command!'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in '<top (required)>'
from /home/deploy/appname/bin/rails:9:in 'require'
from /home/deploy/appname/bin/rails:9:in '<top (required)>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in 'load'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in 'call'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in 'call'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/lib/spring/client.rb:30:in 'run'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/bin/spring:49:in '<top (required)>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in 'load'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in '<top (required)>'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
from /home/deploy/.rbenv/versions/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
from /home/deploy/appname/bin/spring:13:in '<top (required)>'
from bin/rails:3:in 'load'
from bin/rails:3:in '<main>'
Edit
And this is the file causing the error :
/home/deploy/appname/app/controllers/users/confirmations_controller.rb
class Users::ConfirmationsController < Devise::ConfirmationsController
GET /resource/confirmation/new
def new
super
end
POST /resource/confirmation
def create
super
end
GET /resource/confirmation?confirmation_token=abcdef
def show
super
end
protected
The path used after resending confirmation instructions.
def after_resending_confirmation_instructions_path_for(resource_name)
super(resource_name)
end
The path used after confirmation.
def after_confirmation_path_for(resource_name, resource)
super(resource_name, resource)
end
end
The error seems to come from Devise auto generated files but I cannot figure out why it happens only in prodcution mode.
I think you tried to override the devise default behaviour using rails generate devise:controllers and you may have changed them badly.
Please be sure that:
You need to override the default controllers, unless you can remove controllers/users folder (If the name of your model you applied Devise on is Users)
Check syntax in all the files in controller/users.

Paperclip Gem - undefined method '_image_post_process_callbacks'

I have an application on Heroku that uses the Paperclip gem that recently had some issues - and I'm not 100% sure on what it was that caused it. I have the application working locally (including the image upload) - but I get an 'Application Error' page on the heroku url, and when I try to access the heroku console with heroku run rails c it gets an error of:
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/dynamic_matchers.rb:26:in 'method_missing': undefined method '_image_post_process_callbacks' for #<Class:0x007f8aaf5d2fa0> (NoMethodError)
A little background on the issue - another developer was working on creating an image upload model - which was named 'Images' - which I think caused problems with Paperclip, and wouldn't allow me to run a Rails migration. When I tried it said there was an issue with the 'Images' table, so after finding a similar situation online, I commented out the body of the 'def change' within the create_images migration - which now looks like so:
class CreateImages < ActiveRecord::Migration
def change
# create_table :images do |t|
# t.attachment :file
# end
end
end
I then ran another migration - started my server locally and everything was working. I then pushed my changes to heroku, did a rake db:migrate for good luck - and the heroku url is still showing 'Application Error'
If anyone has any idea of possible causes of these issues, it would be greatly appreciated! Thanks for reading!
EDIT
After running heroku run rails c I get this output.
Running rails c on independentskiermag... up, run.7049
Routing about
Routing terms-of-service
Routing privacy-policy
Routing contact
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/dynamic_matchers.rb:26:in 'method_missing': undefined method '_image_post_process_callbacks' for #<Class:0x007f9ff5864330> (NoMethodError)
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:785:in 'get_callbacks'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:647:in 'set_callback'
from (eval):2:in 'before_image_post_process'
from /app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.3.2/lib/paperclip/validators.rb:67:in 'create_validating_before_filter'
from /app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.3.2/lib/paperclip/validators.rb:60:in 'block in validate_before_processing'
from /app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.3.2/lib/paperclip/validators.rb:58:in 'each'
from /app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.3.2/lib/paperclip/validators.rb:58:in 'validate_before_processing'
from /app/vendor/bundle/ruby/2.0.0/gems/paperclip-4.3.2/lib/paperclip/validators/attachment_content_type_validator.rb:84:in 'validates_attachment_content_type'
from /app/app/models/image.rb:4:in '<class:Image>'
from /app/app/models/image.rb:1:in '<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 'require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 'block in require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in 'load_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 'require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:360:in 'require_or_load'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:317:in 'depend_on'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:233:in 'require_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:472:in 'block (2 levels) in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:471:in 'each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:471:in 'block in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:469:in 'each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:469:in 'eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:346:in 'eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in 'each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in 'block in <module:Finisher>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in 'instance_exec'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in 'run'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:in 'block in run_initializers'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in 'block in tsort_each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in 'block (2 levels) in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in 'each_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in 'block in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in 'each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in 'each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in 'tsort_each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:54:in 'run_initializers'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application.rb:352:in 'initialize!'
from /app/config/environment.rb:5:in '<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 'require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 'block in require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in 'load_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 'require'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application.rb:328:in 'require_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:142:in 'require_application_and_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:67:in 'console'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in 'run_command!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in '<top (required)>'
from /app/bin/rails:8:in 'require'
from /app/bin/rails:8:in '<main>'
First off, if you need to undo a migration on Heroku, you will need to un-comment out the body of your migration, push to Heroku, then run heroku run rake db:rollback in order to undo it and get your application working again in the interim.
If you are still having trouble, post the errors and any relevant code in your post.

NoMethodError: undefined method `[]' for nil:NilClass for assets:precompile on heroku

An app using devise and omniauth is working well on localhost, but when I deploy it on heroku, I get an error:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/config/initializers/omniauth.rb:6:in `block in <top (required)>'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/omniauth-1.2.2/lib/omniauth/builder.rb:6:in `initialize'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:43:in `new'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:43:in `build'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `block in build'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `each'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `inject'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `build'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/engine.rb:498:in `app'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application/finisher.rb:36:in `block in <module:Finisher>'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/config/environment.rb:5:in `<top (required)>'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:276:in `require_environment!'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:379:in `block in run_tasks_blocks'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.2.2/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:my-app.git
! [remote rejected] master -> master (pre-receive hook declined)
Here is Gemfile and omniauth files:
#Gemfile:
#....
gem 'google-api-client'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'devise'
#.....
#config/initializers/omniauth.rb
# probably this isn't necessary
if Rails.env.production?
OmniAuth.config.full_host = 'https://my-app.herokuapp.com'
end
# but it is necessary
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, $ga_client['client_id'], $ga_client['client_secret'],
{ scope: 'userinfo.profile, userinfo.email, analytics', access_type: 'offline', prompt: 'consent' }
)
end
In your code, $ga_client is nil. You are not defining such an array anywhere in your file and, in case is defined in other place, it's not loaded at the time this initializer is executed.
Try setting the client_id and client_secret with environment variables, as recommended in the docs.
provider :google_auth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET']
The globals variables weren't initialized:
# but it is necessary
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, $ga_client['client_id'], $ga_client['client_secret'],
{ scope: 'userinfo.profile, userinfo.email, analytics', access_type: 'offline', prompt: 'consent' }
)
end
# ops $ga_client is nil
I discovered it when I replaced the code above with:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"]
end
I was having the same problem. The cause of this problem is that Rails uses a database system called sqlite3, Heroku does not use this database. To fix this, go into your Gemfile and scroll down until you see something which will look a bit like this
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
end
Note: If you are using any versions lower than Rails 4.0.0, you will not have this group, simply create it.
Now somewhere at the top of your Gemfile, will be a line which says
gem 'sqlite3'
Move this line into the Development, Test Group This now will only run in development. You can now try creating your Heroku app again by writing
$ heroku create
Then you may need to migrate your database. Do this by running
$ rake db:migrate
Now push to Heroku
$ heroku push
That should work!
Hope I helped ;)

rspec & rails 3 cannot find model object

I'm trying to put some specs around a new rails 3 project I am working on, and my first test doesn't seem to be able to find a model.
I've installed rspec from the command line using:
sudo gem install rspec --pre
and then I put the following in my Gemfile
gem "rspec-rails", ">= 2.0.0.beta.1"
But when I run my test I get
./spec/models/world_spec.rb:1: uninitialized constant World (NameError)
rake aborted!
Command /opt/local/bin/ruby -Ilib -Ispec "./spec/models/world_spec.rb" failed
/opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/rspec/core/rake_task.rb:71:in 'define'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in 'verbose'
/opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/rspec/core/rake_task.rb:57:in 'send'
/opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/rspec/core/rake_task.rb:57:in 'define'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in 'call'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in 'execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in 'each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in 'execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in 'invoke_with_call_chain'
/opt/local/lib/ruby/1.8/monitor.rb:242:in 'synchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in 'invoke_with_call_chain'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in 'invoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in 'invoke_task'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in 'top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in 'each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in 'top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in 'standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in 'top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in 'run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in 'standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in 'run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/local/bin/rake:19:in 'load'
/opt/local/bin/rake:19
My spec is in spec/models/world_spec.rb, and looks like
describe World, "#hello" do
it "should be invalid" do
World.new.should be_invalid?
end
end
I tried adding a line like require "app/model/world" and require "world" but to no success.
Does anyone know what I'm doing wrong?
Seems in rails 3 I need to require 'spec_helper'
require 'spec_helper'
describe World do
it "should be invalid" do
World.new.should be_invalid?
end
end
But that might just be because I'm running it from rake spec if you're using watchr or some other mechanism you might be able to get that done for you.

Resources