undefined method `each' for false:FalseClass - ruby-on-rails

When I do rake db:migrate I get this error:
rake db:migrate
rake aborted!
NoMethodError: undefined method `each' for false:FalseClass
/home/chirag/social-login-in-rails/config/application.rb:25:in `<class:Application>'
/home/chirag/social-login-in-rails/config/application.rb:10:in `<module:SociaLoginRails>'
/home/chirag/social-login-in-rails/config/application.rb:9:in `<top (required)>'
/home/chirag/social-login-in-rails/Rakefile:4:in `require'
/home/chirag/social-login-in-rails/Rakefile:4:in `<top (required)>'
/home/chirag/.rvm/gems/ruby-2.0.0-p0/bin/ruby_executable_hooks:15:in `eval'
/home/chirag/.rvm/gems/ruby-2.0.0-p0/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
I have cloned this app :- https://github.com/mohitjain/social-login-in-rails

Rename the file 'social_keys_example.yml' to 'social_keys.yml' and put your app keys then restart the sever, it will work

in config/application.rb
change
social_keys = File.join(Rails.root, 'config', 'social_keys.yml')
to
social_keys = File.join(Rails.root, 'config', 'social_keys_example.yml')

follow the instructions
http://codebeerstartups.com/2013/10/social-login-integration-with-all-the-popular-social-networks-in-ruby-on-rails/
In the config directory there is a file ie social_keys.yml. You need
to specify all the social keys there. Make sure have restarted the
application after making any change in that file.
Here are the urls from where you can create an app and get the keys

Related

Could not run Rake Task in Production

I have a rake task which is called by a third party service. In my application I need to set Customer before starting the application. I could not access the model variable from the rake task. But this happens only in Production not in Development. When I run
RAILS_ENV = 'production' rake auth:tester
I get the followng error.
rake aborted!
Unable to autoload constant CUSTOMER, expected /home/suganya/academics/tsg-mcds-server/app/models/customer.rb to define it
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:495:in `load_missing_constant'
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:184:in `const_missing'
/home/suganya/academics/tsg-mcds-server/config/initializers/customer_config.rb:11:in `xml'
/home/suganya/academics/tsg-mcds-server/config/initializers/customer_config.rb:38:in `set_customer_settings'
/home/suganya/academics/tsg-mcds-server/config/initializers/customer_config.rb:710:in `<top (required)>'
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `block in load'
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
/home/suganya/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.2.7.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
I have referred all the related questions. When I enable in poduction.rb
config.threadsafe!
config.dependency_loading = true if $rails_rake_task
I get the following error.
undefined method `threadsafe!' for #<Rails::Application::Configuration:0x00000004aebdf8>
Also I tried
Rails.application.eager_load!
this is my rake task:
namespace :authentication do
desc "Automatically runs authentication tester"
task :tester => :environment do
Rake.application.rake_require "#{Rails.root}/config/initialize_customer_in_development.rb"
begin
AuthenticationTester.perform
rescue
SystemEvent.error(50049, "Authentication Tester Finished Unsuccessfully.")
end
end
end
Nothing helped. please help to solve this problem.

rake db:test:prepare erroring out due to PG error

Some of my rSpec tests are failing and I suspect it's due to the test database not being cleared out. When I try to run rake db:test:prepare, I'm getting the error below (i'm in Rails 3.2). Clearly, this looks like some kind of Postgres issue, looks like the rake task is trying to drop the test database so it can repopulate it. Production database schema loads fine.
I've looked for the rake task in lib/tasks/ but I haven't been able to find it. Anyone have any idea on what's going on?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
Figured it out. My database.yml file for the development environment was set like this:
database: <%= ENV['DATABASE_NAME_TEST'] %>
The rake task was looking for an environmental variable that did not exist.

Error instantiating mechanize object

I have no idea what the problem is on this. I'm trying this in the rails console:
>> agent = Mechanize.new
NoMethodError: undefined method `user' for nil:NilClass
I added gem 'mechanize' and did a bundle install. I did require 'mechanize'. I also tried require 'nokogiri' below that, and every time I get the same error. I've tried 4 or 5 different ways to instantiate a new mechanize object and haven't been able to find one.
I searched my entire rails app for the string '.user' and couldn't find any. Not sure what the deal is here. Any ideas?
Thanks
EDIT
Full Stack trace
NoMethodError: undefined method `user' for nil:NilClass
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/net-http-persistent-2.9.2/lib/net/http/persistent.rb:866:in `proxy='
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:1189:in `set_proxy'
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/mechanize-2.7.2/lib/mechanize.rb:204:in `initialize'
from (irb):5:in `new'
from (irb):5
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands/console.rb:47:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands/console.rb:8:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands.rb:41:in `<top (required)>'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `require'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
You're not doing anything wrong: the version of mechanize that came out a few days ago is buggy. I solved that error just updating the gem (i.e., with bundle update mechanize).

uninitialized constant APN::App::RAILS_ENV

I'm struggling with this error after I fire the command rake apn:notifications:deliver on the APN on Rails gem that I've installed.
It's barking about the RAILS_ENV variable. I've tried a couple of forks that change RAILS_ENV to Rails.env but I still get the same error. I've posted my issue over on that repo hoping I might get somewhere.
I don't know enough about rails to dig in any further. I'm hoping someone could point me in the right direction so that I can a) better understand what went wrong and b) fix the problem.
I am using bundler and I'm pointing my gem file to the git repo: rake apn:notifications:deliver
air:apnapp azcoov$ rake apn:notifications:deliver --trace
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/version.rb:2: warning: already initialized constant VERSION
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
rake aborted!
uninitialized constant APN::App::RAILS_ENV
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:11:in `cert'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:22:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:32:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `each'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/rails/../tasks/apn.rake:7
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => apn:notifications:deliver
Which version of Rails to you use? I just ran into this issue too. My Rails knowledge is not very deep, but it seems like the problem is deprecation of RAILS_* environment variables. I use Rails 3.1.0 and I do NOT have:
RAILS_ROOT/ENV/blah
in my environment. Instead, I have:
Rails.root/env/blah
When I replace RAILS_ENV with Rails.env in app/models/apn/app.rb the problem goes away.
So, is this gem compatible with Rails 3.1.0??? It seems not. Is there a workaround that will allow its use in a Production environment? Maybe define somewhere:
APN::App::RAILS_ENV = Rails.env
But where?
UPDATE:
I got it working with a workaround described by garyfoster here: https://github.com/PRX/apn_on_rails/issues/53.
To summarize, three things:
1) Add this ghetto hack to your config/environment.rb file:
APN::App::RAILS_ENV = Rails.env
2) Insert your certs in the APN::App table. I wrote a one-time rake task for that:
task :init_apn_certs => [:environment] do # NOTE: One-time task...
print "Creating APN::App with certs..."
app = APN::App.create(:apn_dev_cert => Rails.root.join('config', 'apple_push_notification_development.pem').read,
:apn_prod_cert => Rails.root.join('config', 'apple_push_notification_production.pem').read)
puts (app.valid? ? "done" : "failed")
end
3) Write your own rake task that bypasses the APN::App.send_notifications method, as that barfs with another error (something about '/config/apple_push_notification_development.pem' not existing). My code for it:
task :deliver_notifications => [:environment] do
print "Delivering APNs for app ids..."
apps = APN::App.all
apps.each do |app|
app.send_notifications
print app.id.to_s + "..."
end
puts "done."
end
Or, if you have only one app, you can just do this and be done with it:
task :deliver_notifications => [:environment] do
APN::App.first.send_notifications
end
DISCLAIMER: I'm yet to test this on Staging and Production (will do so by the end of the week), but I see no reason why it shouldn't work.

issue installing active admin - rails 3.0.3 - uninitialized constant Formtastic::SemanticFormHelper

I'm trying to add activeadmin to my rails 3.0.3 app.
I'm following the instructions here
When I run - rake db:migrate I get the following error -
rake aborted!
uninitialized constant Formtastic::SemanticFormHelper
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `eval'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/resource_controller.rb:1:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:3:in `<module:Dashboards>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:2:in `<module:ActiveAdmin>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:1:in `<top (required)>'
(eval):1:in `generate_dashboard_controller'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `eval'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `generate_dashboard_controller'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:38:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:147:in `new'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:147:in `find_or_create_namespace'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:282:in `load_default_namespace'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:188:in `load!'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:212:in `routes'
You seem to be missing the formtastic gem. In the current version of active-admin (0.3.2) it is correctly specified as a dependency.
So I hope updating the activeadmin gem (bundle update activeadmin) will fix it.
If that does not fix it, I would add formtastic explicitly to the Gemfile.
Hope this helps.
In rails 3 the Formtastic::SemanticFormHelper became => Formtastic::Helpers::FormHelper
Don't forget to load your lib. By default rails don't load them so you can just uncomment config.autoload_paths += %W(#{config.root}/lib) in your application.rb

Resources