Gem Koala undefined methods 'get_object' - ruby-on-rails-3

I wanted to use Koala Gem to connect to Facebook api but I faced some problems.
Before I used Koala, I used omniauth-facebook to implement the SSO of my app.
And then I added gem koala in Gemfile and run bundle install.
In my `user.rb'
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
def facebook
#facebook = Koala::Facebook::API.new(oauth_token)
end
And then I go to consoele.
u = User.first
User Load (0.5ms) SELECT "users".* FROM "users" LIMIT 1
=> #<User id: 1, provider: "facebook", uid: "100003544640331", name: "Gary Lai", oauth_token: "AAAB9iQ1zm2oBAA1w3DFBZBC2V73uheQCs43dHpOu1LYsYixqvu...", oauth_expires_at: "2012-10-02 09:55:39", created_at: "2012-07-27 16:41:18", updated_at: "2012-08-03 09:55:42">
It works.
However, when I follow the kaola tutorial, I got this error message.
u.facebook.get_object("me")
NoMethodError: undefined method `get_object' for #<Koala::Facebook::API:0x007fb07ab1e108>from (irb):8
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Why I got this error message ?

Finally, I solved this problem. Cause my koala version were 1.0. Therefore I have to use gem 'koala', :git => 'https://github.com/arsduo/koala.git'

Related

how can I send an email from an IronWorker for a rails3 app?

I followed all the docs for IronWorkerNG::Client.new and rails:
https://github.com/iron-io/iron_worker_rails_example
My .worker file is doing:
runtime 'ruby'
name 'CompanyList'
merge_gem 'activerecord'
merge_gem 'actionmailer'
merge_gem 'pg'
merge_gem 'aws-s3'
dir '../app/models'
file '../app/mailers/result_mailer.rb'
file "../app/views/result_mailer/email.html.erb", "result_mailer"
exec 'company_list.rb'
remote
and my ruby file does:
require 'action_mailer'
require 'active_record'
require 'aws/s3'
require 'pg'
require 'models/company_list.rb'
require 'result_mailer.rb'
puts "Starting CompanyList worker at #{Time.now}"
ActiveRecord::Base.establish_connection(params['database'])
mailer_config = params['mailer'].inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
#ActionMailer::Base.prepend_view_path('.')
ActionMailer::Base.view_paths = ['.']
ActionMailer::Base.smtp_settings = mailer_config
ActionMailer::Base.delivery_method = :smtp
But everytime I get this error:
/task/__gems__/gems/actionmailer-2.3.18/lib/action_mailer/base.rb:433:
in `method_missing': undefined method `email' for ResultMailer:Class
(NoMethodError)
from /task/models/company_list.rb:16:in `process_file'
from /task/company_list.rb:18:in `<top (required)>'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from __runner__.rb:213:in `<main>'
and ResultMailer DOES have an email method:
class ResultMailer < ActionMailer::Base
def email
to = 'andrew#testdomain.com'
mail :from => 'test#testdomain.com', :to => to, :subject => "Test"
end
end
any idea why action_mailer base line 433 is throwing that error? I can call ResultMailer.email.deliver from the console on my local system just fine. This error is on production with heroku and iron.io.
ah, sometimes writing out the question on stackoverflow makes you see the problem. I needed:
merge_gem "activerecord", "=3.2.8"
merge_gem 'actionmailer', '=3.2.8'
without the 3.2.8 version it was using an old old version of action mailer.

Mongoid3 + FactoryGirl Incompatible?

I just upgrade to Mongoid3 and Im getting a TON of these errors:
TypeError:
can't convert String into Integer
The issue is always when Im trying to build a model that belongs_to another model and I assign the referenced model:
#entry = FactoryGirl.create(:entry_image, user_id: #user.id, day: 18, month: 6)
It seems to be the "user_id: #user.id" part. Ive tried:
#entry = FactoryGirl.build(:entry_image, day: 18, month: 6)
#entry.user = #user
#entry.save
Same error every time.
Here is the factory file:
FactoryGirl.define do
factory :user do
name 'Test User'
email 'example#example.com'
password 'please'
password_confirmation 'please'
pin '1234'
default_time_zone 'America/New_York'
end
...
Im using devise, here is the controller macro we run:
module ControllerMacros
def login_user
before(:each) do
#request.env["devise.mapping"] = Devise.mappings[:user]
#user = FactoryGirl.create(:user)
#user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module
sign_in #user
end
end
end
Here is the full stack trace:
> 1.9.3p194 :016 > user = User.all[0]
=> #<User _id: 503e9c807adf9d6551000001, _type: nil, email: "joe#email.com", encrypted_password: "$5a$10$Mt1kx/TtbDma4gVtcTLdLeeP6tcSiF2AJkjeJmv73/U5OWF.M34v.", remember_created_at: 2012-08-29 23:30:17 UTC, sign_in_count: 3, current_sign_in_at: 2012-08-29 23:30:17 UTC, last_sign_in_at: 2012-08-29 22:49:57 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", s3_access_key: #<Moped::BSON::Binary type=:generic length=24>, s3_secret_key: #<Moped::BSON::Binary type=:generic length=48>, pin: nil, default_time_zone: "America/New_York", name: "Joe Smith">
1.9.3p194 :017 > e = FactoryGirl.create(("entry_image").to_s, user_id: user.id, items: [ FactoryGirl.build(:image, user_id: user.id) ])
TypeError: can't convert String into Integer
from /Users/lee/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/set.rb:185:in `include?'
from /Users/lee/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/set.rb:185:in `include?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:140:in `block (3 levels) in cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:139:in `each'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:139:in `block (2 levels) in cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/relations/accessors.rb:103:in `without_autobuild'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:133:in `block in cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:131:in `each_pair'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:131:in `cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:95:in `run_callbacks'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations.rb:179:in `valid?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/validations.rb:78:in `valid?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations.rb:187:in `invalid?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/persistence/insertion.rb:22:in `prepare'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
... 4 levels...
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/evaluation.rb:15:in `[]'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/evaluation.rb:15:in `create'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:9:in `tap'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:9:in `result'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory.rb:42:in `run'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:23:in `block in run'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.0/lib/active_support/notifications.rb:125:in `instrument'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:22:in `run'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method'
from (irb):17
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Rails 3 - URL Helpers With Scoped Resource

I have a scoped resource in my routes file:
scope :module => "physical" do
resources :mymodels
end
Using '> rake routes' I get the standard routes, including:
mymodel GET /mymodels/:id(.:format) {:action=>"show", :controller=>"physical/mymodels"}
However when I use the console (and this is what's failing in my tests) to get the url for instances of Mymodel I get errors:
> m = Physical::Mymodel.new
> => {...model_attributes...}
> m.save
> => true
> app.url_for(m)
> NoMethodError: undefined method `physical_mymodel_url' for #<ActionDispatch::Integration::Session:0x00000105b15228>
from /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing'
from /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
from /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/url_for.rb:133:in `url_for'
from (irb):13
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
This might be a gotcha, but Mymodel is also a subclass using the standard Rails single table inheritance.
Any thoughts? Why is it looking for physical_mymodel_url instead of mymodel_url? Any ideas for workarounds so that I can still use the unprefixed routes?
You're only using the scope to tell it the module where the controller can be found in. If you want to use the physical prefix on your routes then you could do this:
scope :module => "physical", :as => "physical" do
resources :mymodel
end
Alternatively, you could just use the namespace method which will do the same thing:
namespace :physical do
resources :mymodel
end

mysql2 rails3.1 error

I am on windows xp, with rails 3.1
and i use mysql2 0.2.6
but when i
when i try to make a request like:
Product.all
i got this responce:
irb(main):001:0> Product.all
←[1m←[36m (0.0ms)←[0m ←[1mSHOW TABLES←[0m
←[1m←[35m (0.0ms)←[0m describe `products`
ArgumentError: wrong number of arguments (3 for 2)
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:634:in `select'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:470:in `find_by_sql'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation.rb:111:in `to_a'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:155:in `all'
from D:in `all'
from (irb):1
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
my controller:
def index
#products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #products }
end
end
my models :
class Product < ActiveRecord::Base
define_index do
indexes brand
indexes name
indexes denomination
end
end
mysql2 0.2.6 isn't compatible with Rails 3.1.
You should either downgrade Rails to 3.0.7 or upgrade mysql2 to 0.3.1.

Rails 3 Setting Up Action Mailer

Everything was going so well...
gem 'mail' is installed
enter > $ rails g scaffold user name:string email:string
enter > $ rake db:migrate (fine I can see it on http://localhost:3000/users/new) then...
enter > $ rails g mailer user_mailer
On this command I get this huge error - what is it and how do I resolve it?
Users/mailer_app/config/initializers/setup_mail.rb:14: uninitialized
constant DevelopmentMailInterceptor (NameError)
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/engine.rb:201
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/engine.rb:200:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/engine.rb:200
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `instance_exec'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `run'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:50:in `run_initializers'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `run_initializers'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:134:in `initialize!'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in `send'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing'
from /Users/liam_carey/Documents/Aptana Studio 3 Workspace/mailer_test/config/environment.rb:5
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:103:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:103:in `require_environment!'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:16
from script/rails:6:in `require'
from script/rails:6
user:mailer_app $
Here is the contents of my config/initializers/setup_mail.rb
Am using Heroku and Sendgrid and have installed the plug-in.
Did I need to install the 'mail' gem first, the documentation doesn't mention it??
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain
:user_name => "apxxxxx#heroku.com",
:password => "9XXXXXXXXX",
:domain => "www.myapp.com",
}
I know what the issue is now - there is no comma after the user-name and password entries!