1
votes

I'm trying to integrate facebook authentication with devise.

I used this tutorial (http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin) and got it to work locally, but I keep getting an error when I push to heroku. I have already changed the links in the Facebook dev/apps part to the actual domain.

I have the following code in production.rb. For "app_domain" part, I've tried to put in all types of app domain variations (the domain, domain.com, heroku app name, etc.) but I have no idea what should go there.

I'm a new coder, so would appreciate any help!

# Email for omniauth facebook auth
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => config.app_domain }
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com', 
port: '587',
enable_starttls_auto: true,
user_name: 'someuser',
password: 'somepass',
authentication => :plain,
domain => 'somedomain.com'
}

NoMethodError: undefined method `app_domain' for

   /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie/configuration.rb:95:in

method_missing' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environments/production.rb:100:in block in ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie.rb:210:in instance_eval' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie.rb:210:in configure' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environments/production.rb:1:in <top (required)>' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inrequire' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in block in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:inload_dependency' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:594:in block (2 levels) in ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:593:in each' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:593:in block in ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in instance_exec' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in run' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:in block in run_initializers' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:44:in each' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:44:in tsort_each_child' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:54:in run_initializers' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:288:in initialize!' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environment.rb:5:in ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inblock in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in load_dependency' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inrequire' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:in require_environment!' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:367:in block in run_tasks_blocks' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:55:in `block (2 levels) in define' Tasks: TOP => environment (See full trace by running task with --trace) ! ! Precompiling assets failed.

1

1 Answers

1
votes

Your error message, "undefined method `app_domain'" stems from this line:

config.action_mailer.default_url_options = { :host => config.app_domain }

Just as it says, you haven't assigned an app_domain property on your config option. Action Mailer is the part of Rails that sends emails, and it uses this setting to generate links back to your application.

You could just add config.app_domain = "myapp.herokuapp.com" to the top of your config/environments/production.rb file. But this is hard-coded; an alternative is to use an environment variable instead.

Heroku uses their config command for this; run heroku config:set APP_DOMAIN=myapp.herokuapp.com in the terminal to set it, and then use ENV['APP_DOMAIN'] in your Ruby app to access it. So your config line would look like this:

config.action_mailer.default_url_options = { :host => ENV['APP_DOMAIN'] }

Finally, you have a domain setting as part of the smtp_settings block at the bottom. You might want to make that use your new setting too.