'Mongo::OperationFailure' for some actions in Rails - ruby-on-rails

I'm new to Mongo. I've installed Mongodb from this source. I'm using the mongodb for Rails application. The app loads fine after starting the mongodb and rails. However, it fails when I try to login. The same thing happens when I try to perform some operations in rails console.
Here the model code:
def self.authenticate(email, password)
user = find(:first, :conditions => {:email => email})
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
user
else
nil
end
end
Its failing at if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
Here is the short error:
Database command 'create' failed: {"ok"=>0.0, "errmsg"=>"collection already exists", "code"=>48}
And, the full application error trace:
mongo (1.3.1) lib/mongo/db.rb:506:in command'
mongo (1.3.1) lib/mongo/db.rb:284:increate_collection'
mongoid (2.2.1) lib/mongoid/collections/master.rb:41:in initialize'
mongoid (2.2.1) lib/mongoid/collection.rb:127:innew'
mongoid (2.2.1) lib/mongoid/collection.rb:127:in master'
mongoid (2.2.1) lib/mongoid/collection.rb:60:infind_one'
mongoid (2.2.1) lib/mongoid/contexts/mongo.rb:164:in first'
mongoid (2.2.1) lib/mongoid/criteria.rb:42:inone'
mongoid (2.2.1) lib/mongoid/criterion/inclusion.rb:104:in find'
mongoid (2.2.1) lib/mongoid/finders.rb:83:infind'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in send_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:151:inprocess_action'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:11:in process_action'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:inblock in process_action'
activesupport (3.0.3) lib/active_support/callbacks.rb:435:in _run__902337259577170033__process_action__4476240526817474042__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:inprocess_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in block in process_action'
activesupport (3.0.3) lib/active_support/notifications.rb:52:inblock in instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:ininstrument'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in process_action'
actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:inprocess_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:120:in process'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:inprocess'
actionpack (3.0.3) lib/action_controller/metal.rb:138:in dispatch'
actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:indispatch'
actionpack (3.0.3) lib/action_controller/metal.rb:178:in block in action'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:incall'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in dispatch'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:incall'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:inblock in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:75:in optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:inrecognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:incall'
mongoid (2.2.1) lib/rack/mongoid/middleware/identity_map.rb:33:in block in call'
mongoid (2.2.1) lib/mongoid.rb:130:inunit_of_work'
mongoid (2.2.1) lib/rack/mongoid/middleware/identity_map.rb:33:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in call'
rack (1.2.4) lib/rack/methodoverride.rb:24:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in block in call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in call'
rack (1.2.4) lib/rack/sendfile.rb:106:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:incall'
railties (3.0.3) lib/rails/rack/logger.rb:13:in call'
rack (1.2.4) lib/rack/runtime.rb:17:incall'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in call'
rack (1.2.4) lib/rack/lock.rb:11:inblock in call'
rack (1.2.4) lib/rack/lock.rb:11:in synchronize'
rack (1.2.4) lib/rack/lock.rb:11:incall'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in call'
railties (3.0.3) lib/rails/application.rb:168:incall'
railties (3.0.3) lib/rails/application.rb:77:in method_missing'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:incall'
rack (1.2.4) lib/rack/content_length.rb:13:in call'
rack (1.2.4) lib/rack/handler/webrick.rb:52:inservice'
/Users/reonios/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/webrick/httpserver.rb:138:in service'
/Users/reonios/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/webrick/httpserver.rb:94:inrun'
/Users/reonios/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Any help is highly appreciated.

After checking the code and googling I found that a special character was sent in every request. My request parameters were like this:
{
"utf8"=>"✓",
"authenticity_token"=>"cAcdDOzfBgalF5em+97mTKw9DAjymfmEmG6hc+dDqhQ=",
"email"=>"super_admin_user#test.com",
"password"=>"[FILTERED]",
"commit"=>"Login"
}
Not sure what triggered 'âœ'. But one of the post in google says, there is a bug related to this present in the 2.2 series and that is got fixed with later versions.
So, I found my mongoid version to be 2.2.1 and once I had it upgraded the problem got resolved.
NOTE: Am new to mongoid and gave a solution with minimal knowledge. Please add details if needed.

Related

'Nesting too deep' error while retrieving JSON using HTTParty

I am writing a very simple proxy wrapper for the reddit api so I can make cross domain JSONP requests (reddit does not allow JSONP calls to my knowledge).
I am using the HTTParty gem to make the call out and retrieve the response, which I immediately render out as json.
I am retrieving the subreddit json perfectly fine so far with this as my route:
match "r/:name" => "api#subreddit"
... and this as my controller action:
def subreddit
render :json => HTTParty.get("http://www.reddit.com/r/" + params[:name] + "/.json"), :callback => params[:callback]
end
As an example, the JSON that comes back is similar to this: http://www.reddit.com/r/pics/.json
My problem is when I attempt to grab the comments for a particular thread.
My route is as so:
match "r/:name/comments/:id" => "api#comments"
... and my controller action is this:
def comments
render :json => HTTParty.get("http://www.reddit.com/r/" + params[:name] + "/comments/" + params[:id] + "/.json"), :callback => params[:callback]
end
The JSON that I want back can be seen here: http://www.reddit.com/r/pics/comments/rhzgc/.json
When I call this action, however, I receive the following error message:
MultiJson::DecodeError in ApiController#comments
Nesting of 20 is too deep
The full stack trace follows:
json (1.6.6) lib/json/common.rb:148:in `parse'
json (1.6.6) lib/json/common.rb:148:in `parse'
multi_json (1.2.0) lib/multi_json/engines/json_common.rb:9:in `decode'
multi_json (1.2.0) lib/multi_json.rb:81:in `decode'
httparty (0.8.1) lib/httparty/parser.rb:116:in `json'
httparty (0.8.1) lib/httparty/parser.rb:136:in `parse_supported_format'
httparty (0.8.1) lib/httparty/parser.rb:103:in `parse'
httparty (0.8.1) lib/httparty/parser.rb:66:in `call'
httparty (0.8.1) lib/httparty/request.rb:222:in `parse_response'
httparty (0.8.1) lib/httparty/request.rb:192:in `handle_response'
httparty (0.8.1) lib/httparty/request.rb:75:in `perform'
httparty (0.8.1) lib/httparty.rb:391:in `perform_request'
httparty (0.8.1) lib/httparty.rb:343:in `get'
httparty (0.8.1) lib/httparty.rb:423:in `get'
app/controllers/api_controller.rb:12:in `comments'
actionpack (3.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.1) lib/active_support/callbacks.rb:416:in `_run__2872109728488784816__process_action__2261783022290592822__callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.1) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.1) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.1) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
activerecord (3.1.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.1) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.1) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:89:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:532:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.6) lib/rack/etag.rb:23:in `call'
rack (1.3.6) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.6) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.6) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.1) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.1) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.6) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.1) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.6) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.6) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.6) lib/rack/lock.rb:15:in `call'
actionpack (3.1.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.1) lib/rails/engine.rb:456:in `call'
railties (3.1.1) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.6) lib/rack/handler/webrick.rb:59:in `service'
/Users/emcummings/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/emcummings/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/emcummings/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
What am I doing wrong here? If the JSON is too big to parse (I find that sort of hard to believe!) what can I do?
EDIT:
Looks like dropping back to the standard NET::HTTP lib solved my problem:
uri = URI.parse("http://www.reddit.com/r/pics/comments/rhzgc/.json")
response = Net::HTTP.get_response(uri)
render :json => response.body, :callback => params[:callback]
#OK!
... but I still am curious why I am failing this same call with HTTParty!
Thanks for the help!
It's not that the JSON is too large. It's nested too deeply. HTTParty tries to decode the results that it gets automatically. Following your stack trace, and the HTTParty dependencies, it relies on multi_json which is using the json gem.
Inside of json there is lib/json/pure/parser.rb. The default max depth set is set in there, specifically on line 79. Something in your returned JSON is 20+ levels deep, triggering the exception.
if !opts.key?(:max_nesting) # defaults to 19
#max_nesting = 19
Switched to the OJ JSON parser by adding the following to my Gemfile:
gem 'oj'
and this issue resolved itself.
It looks like this can be worked around by calling to_json with the max_nesting option set.
json = obj.to_json(max_nesting: 50)

Cancan permission

I have a rails app that is is using cancan permission and i am trying to block others users from editing another user's dashboard. This has worked for other models but not this one.
profile.rb
belongs_to :dashboard
Dashboard.rb
has_many :profiles
Dashboard_controller
before_filter :authenticate_user!
load_and_authorize_resource :through => :current_profile
Ability.rb
can :manage, Dashboard, :profile => { :user_id => user.id }
When I go to view my dashboard rails gives me the error
undefined method `dashboards'
Any ideas how I can overcome this error?
Full trace
activemodel (3.1.3) lib/active_model/attribute_methods.rb:385:in `method_missing'
activerecord (3.1.3) lib/active_record/attribute_methods.rb:60:in `method_missing'
cancan (1.6.7) lib/cancan/controller_resource.rb:174:in `resource_base'
cancan (1.6.7) lib/cancan/controller_resource.rb:77:in `load_collection?'
cancan (1.6.7) lib/cancan/controller_resource.rb:33:in `load_resource'
cancan (1.6.7) lib/cancan/controller_resource.rb:25:in `load_and_authorize_resource'
cancan (1.6.7) lib/cancan/controller_resource.rb:10:in `block in add_before_filter'
activesupport (3.1.3) lib/active_support/callbacks.rb:439:in `_run__4465164984821190291__process_action__669795061578511304__callbacks'
activesupport (3.1.3) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.3) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.3) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.3) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.3) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
activerecord (3.1.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.3) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.3) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.3) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.3) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:532:in `call'
warden (1.1.0) lib/warden/manager.rb:35:in `block in call'
warden (1.1.0) lib/warden/manager.rb:34:in `catch'
warden (1.1.0) lib/warden/manager.rb:34:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.6) lib/rack/etag.rb:23:in `call'
rack (1.3.6) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/flash.rb:247:in `call'
rack (1.3.6) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.6) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.3) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.1.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.3) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.3) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.6) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.6) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.6) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.6) lib/rack/lock.rb:15:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.3) lib/rails/engine.rb:456:in `call'
rack (1.3.6) lib/rack/content_length.rb:14:in `call'
railties (3.1.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.6) lib/rack/handler/webrick.rb:59:in `service'
/Users/mac/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/mac/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/mac/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
When you use load_authorize_resource Cancan assumes a plural resource (ie that a profile has many dashboards). According to the docs adding :singleton => true turns this off

Error with OAuth2 gem v 0.5.0

I get a very opaque error with the following code:
client = OAuth2::Client.new(
"#{FACEBOOK_CONFIG['application_id']}", "#{FACEBOOK_CONFIG['secret_key']}",
:site => 'https://graph.facebook.com'
)
token = OAuth2::AccessToken.new(client, fb_token)
token.get('/me')
when I execute token.get('/me'), I get the following output:
OAuth2::Error Exception: OAuth2::Error
This code works fine with v0.4.1 but fails with v0.5.0
Here is the stack trace:
OAuth2::Error
Rails.root: /Users/myname/Sites/mysite
Application Trace | Framework Trace | Full Trace
oauth2 (0.5.0) lib/oauth2/client.rb:107:in `request'
oauth2 (0.5.0) lib/oauth2/access_token.rb:98:in `request'
oauth2 (0.5.0) lib/oauth2/access_token.rb:105:in `get'
app/models/facebook_session.rb:430:in `get_fb_me'
app/models/facebook_session.rb:45:in `get_fb_user_id'
app/models/facebook_session.rb:258:in `authenticate'
app/controllers/devise/registrations_controller.rb:42:in `create'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:151:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.3) lib/active_support/callbacks.rb:470:in `_run__664618575269127242__process_action__2116611615142804558__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:120:in `process'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.3) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:82:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:in `call'
warden (0.10.7) lib/warden/manager.rb:35:in `block in call'
warden (0.10.7) lib/warden/manager.rb:34:in `catch'
warden (0.10.7) lib/warden/manager.rb:34:in `call'
haml (3.0.25) lib/sass/plugin/rack.rb:41:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:in `call'
activerecord (3.0.3) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.3) lib/rails/application.rb:168:in `call'
railties (3.0.3) lib/rails/application.rb:77:in `method_missing'
railties (3.0.3) lib/rails/rack/debugger.rb:21:in `call'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/Users/myname/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/myname/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/myname/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
I've only used Omniauth recently but it looks like your trace is saying you have something like this in your oauth_helper:
def try_access_token
begin
..
rescue OAuth2::AccessDenied
end
end
If that's the case, try changing OAuth2::AccessDenied to OAuth2::Error. Oauth2::Error provides a .code attribute that you can check to determine if it's an access denied response.
4.1 docs: http://rubydoc.info/gems/oauth2/0.4.1/frames
5.0+ docs: http://rubydoc.info/gems/oauth2/0.5.0/frames
I have the same problem.
Looking at the gem code, it's because the Facebook answer is an HTTP code of 400..599.
when 400..599
e = Error.new(response)
raise e if opts[:raise_errors] || options[:raise_errors]
Sadly, the communication between my server to facebook is using HTTPS, therefore, I haven't been able to intercept the problematic request yet.
UPDATE
I got a 400 error from Facebook :
OAuth "Facebook Platform" "invalid_request" "An active access token must be used to query information about the current user."
UPDATE 2
Interesting discussion here : Facebook access_token invalid?
I ended up rolling oauth2 back to 0.4.1 and my FB login and querying works.

strange error while sending confirmation email through devise on rails 3.0.3, ruby 1.8.7

I am using devise 1.3.4 on Rails 3.0.3 and ruby 1.8.7 for user authentication/authorization and new user creation. (I followed Ryan's railscast on devise and omniauth but also used the confirmable option)
It works just fine when there are no users in the database. However, when I signout the only user and try to create a new one, I get the following error:
undefined method `encode!' for "Confirmation":String
Here's the full stack trace:
ail (2.2.17) lib/mail/fields/unstructured_field.rb:169:in `encode'
mail (2.2.17) lib/mail/fields/unstructured_field.rb:138:in `fold'
mail (2.2.17) lib/mail/fields/unstructured_field.rb:108:in `wrapped_value'
mail (2.2.17) lib/mail/fields/unstructured_field.rb:70:in `do_encode'
mail (2.2.17) lib/mail/fields/unstructured_field.rb:52:in `encoded'
mail (2.2.17) lib/mail/field.rb:122:in `send'
mail (2.2.17) lib/mail/field.rb:122:in `method_missing'
mail (2.2.17) lib/mail/header.rb:190:in `encoded'
mail (2.2.17) lib/mail/header.rb:189:in `each'
mail (2.2.17) lib/mail/header.rb:189:in `encoded'
mail (2.2.17) lib/mail/message.rb:1707:in `encoded'
actionmailer (3.0.3) lib/action_mailer/base.rb:420:in `set_payload_for_mail'
actionmailer (3.0.3) lib/action_mailer/base.rb:400:in `deliver_mail'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
actionmailer (3.0.3) lib/action_mailer/base.rb:399:in `deliver_mail'
mail (2.2.17) lib/mail/message.rb:230:in `deliver'
devise (1.3.4) lib/devise/models/confirmable.rb:50:in `send_confirmation_instructions'
activesupport (3.0.3) lib/active_support/callbacks.rb:425:in `_run_create_callbacks'
activerecord (3.0.3) lib/active_record/callbacks.rb:281:in `create'
activerecord (3.0.3) lib/active_record/persistence.rb:246:in `create_or_update'
activerecord (3.0.3) lib/active_record/callbacks.rb:277:in `create_or_update'
activesupport (3.0.3) lib/active_support/callbacks.rb:418:in `_run_save_callbacks'
activerecord (3.0.3) lib/active_record/callbacks.rb:277:in `create_or_update'
activerecord (3.0.3) lib/active_record/persistence.rb:39:in `save'
activerecord (3.0.3) lib/active_record/validations.rb:43:in `save'
activerecord (3.0.3) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (3.0.3) lib/active_record/transactions.rb:237:in `save'
activerecord (3.0.3) lib/active_record/transactions.rb:289:in `with_transaction_returning_status'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.3) lib/active_record/transactions.rb:204:in `transaction'
activerecord (3.0.3) lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
activerecord (3.0.3) lib/active_record/transactions.rb:237:in `save'
activerecord (3.0.3) lib/active_record/transactions.rb:248:in `rollback_active_record_state!'
activerecord (3.0.3) lib/active_record/transactions.rb:236:in `save'
devise (1.3.4) app/controllers/devise/registrations_controller.rb:16:in `create'
app/controllers/registrations_controller.rb:3:in `create'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:151:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.3) lib/active_support/callbacks.rb:445:in `_run__799082383__process_action__1623385099__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `send'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:120:in `process'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.3) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/mapper.rb:35:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:89:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:in `call'
oa-core (0.2.4) lib/omniauth/strategy.rb:59:in `call!'
oa-core (0.2.4) lib/omniauth/strategy.rb:26:in `call'
oa-core (0.2.4) lib/omniauth/strategy.rb:59:in `call!'
oa-core (0.2.4) lib/omniauth/strategy.rb:26:in `call'
oa-core (0.2.4) lib/omniauth/strategy.rb:59:in `call!'
oa-core (0.2.4) lib/omniauth/strategy.rb:26:in `call'
oa-core (0.2.4) lib/omniauth/builder.rb:30:in `call'
warden (1.0.4) lib/warden/manager.rb:35:in `call'
warden (1.0.4) lib/warden/manager.rb:34:in `catch'
warden (1.0.4) lib/warden/manager.rb:34:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.2) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:in `call'
activerecord (3.0.3) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.2) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.2) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.2) lib/rack/lock.rb:11:in `call'
rack (1.2.2) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.2) lib/rack/lock.rb:11:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.3) lib/rails/application.rb:168:in `call'
railties (3.0.3) lib/rails/application.rb:77:in `send'
railties (3.0.3) lib/rails/application.rb:77:in `method_missing'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.2) lib/rack/content_length.rb:13:in `call'
rack (1.2.2) lib/rack/handler/webrick.rb:52:in `service'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/rahulbaxi/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.2) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.2) lib/rack/server.rb:213:in `start'
railties (3.0.3) lib/rails/commands/server.rb:65:in `start'
railties (3.0.3) lib/rails/commands.rb:30
railties (3.0.3) lib/rails/commands.rb:27:in `tap'
railties (3.0.3) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
Please help me out with this!
String#encode! is new in Ruby 1.9 so its just not there in 1.8.7. So it looks as though the mail gem that you are using has a dependency on 1.9.

NoMethodError in Ruby on Rails calling Class Method from a controller

I'm just learning RoR and have run into my first real bug. Would really appreciate some guidance with it. I am up to the point of creating a user sign in/out feature for a site I am building which will be maintained through sessions. When the sign in form submits it goes to a sessions controller which calls the 'create' method. When it does this it displays this error:
NoMethodError in
SessionsController#create
You have a nil object when you didn't
expect it! You might have expected an
instance of ActiveRecord::Base. The
error occurred while evaluating nil.[]
Here's the code for the create method:
33 def create
34 user = User.authenticate(params[:session][:email],
35 params[:session][:password])
36 if user.nil?
37 flash.now[:error] = "Invalid email/password combination."
38 #title = "Sign in"
39 render 'new'
40 else
41 sign_in user
42 redirect_back_or user
43 end
44 end
The application trace says the error is at
app/controllers/sessions_controller.rb:34:in `create'
So the issue seems to be with the authenticate method. This is a class method defined for my user object. What's weird is that I tested the method in rails console and it works fine. Below is the full trace. Again would be very grateful for some help with this. Thanks you.
Trace:
app/controllers/sessions_controller.rb:34:in
create' actionpack (3.0.4)
lib/action_controller/metal/implicit_render.rb:4:in
send_action' actionpack (3.0.4)
lib/abstract_controller/base.rb:150:in
process_action' actionpack (3.0.4)
lib/action_controller/metal/rendering.rb:11:in
process_action' actionpack (3.0.4)
lib/abstract_controller/callbacks.rb:18:in
block in process_action'
activesupport (3.0.4)
lib/active_support/callbacks.rb:435:in
run_4224187041876590211__process_action_3718750575726612430_callbacks'
activesupport (3.0.4)
lib/active_support/callbacks.rb:409:in
_run_process_action_callbacks'
activesupport (3.0.4)
lib/active_support/callbacks.rb:93:in
run_callbacks' actionpack (3.0.4)
lib/abstract_controller/callbacks.rb:17:in
process_action' actionpack (3.0.4)
lib/action_controller/metal/instrumentation.rb:30:in
block in process_action'
activesupport (3.0.4)
lib/active_support/notifications.rb:52:in
block in instrument' activesupport
(3.0.4)
lib/active_support/notifications/instrumenter.rb:21:in
instrument' activesupport (3.0.4)
lib/active_support/notifications.rb:52:in
instrument' actionpack (3.0.4)
lib/action_controller/metal/instrumentation.rb:29:in
process_action' actionpack (3.0.4)
lib/action_controller/metal/rescue.rb:17:in
process_action' actionpack (3.0.4)
lib/abstract_controller/base.rb:119:in
process' actionpack (3.0.4)
lib/abstract_controller/rendering.rb:41:in
process' actionpack (3.0.4)
lib/action_controller/metal.rb:138:in
dispatch' actionpack (3.0.4)
lib/action_controller/metal/rack_delegation.rb:14:in
dispatch' actionpack (3.0.4)
lib/action_controller/metal.rb:178:in
block in action' actionpack (3.0.4)
lib/action_dispatch/routing/route_set.rb:62:in
call' actionpack (3.0.4)
lib/action_dispatch/routing/route_set.rb:62:in
dispatch' actionpack (3.0.4)
lib/action_dispatch/routing/route_set.rb:27:in
call' rack-mount (0.6.14)
lib/rack/mount/route_set.rb:148:in
block in call' rack-mount (0.6.14)
lib/rack/mount/code_generation.rb:93:in
block in recognize' rack-mount
(0.6.14)
lib/rack/mount/code_generation.rb:68:in
optimized_each' rack-mount (0.6.14)
lib/rack/mount/code_generation.rb:92:in
recognize' rack-mount (0.6.14)
lib/rack/mount/route_set.rb:139:in
call' actionpack (3.0.4)
lib/action_dispatch/routing/route_set.rb:492:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/best_standards_support.rb:17:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/head.rb:14:in
call' rack (1.2.2)
lib/rack/methodoverride.rb:24:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/params_parser.rb:21:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/flash.rb:182:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/session/abstract_store.rb:149:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/cookies.rb:302:incall' activerecord (3.0.4)
lib/active_record/query_cache.rb:32:in
block in call' activerecord (3.0.4)
lib/active_record/connection_adapters/abstract/query_cache.rb:28:in
cache' activerecord (3.0.4)
lib/active_record/query_cache.rb:12:in
cache' activerecord (3.0.4)
lib/active_record/query_cache.rb:31:in
call' activerecord (3.0.4)
lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/callbacks.rb:46:in
block in call' activesupport (3.0.4)
lib/active_support/callbacks.rb:415:in
_run_call_callbacks' actionpack
(3.0.4)
lib/action_dispatch/middleware/callbacks.rb:44:in
call' rack (1.2.2)
lib/rack/sendfile.rb:107:in call'
actionpack (3.0.4)
lib/action_dispatch/middleware/remote_ip.rb:48:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/show_exceptions.rb:47:in
call' railties (3.0.4)
lib/rails/rack/logger.rb:13:incall'
rack (1.2.2) lib/rack/runtime.rb:17:in
call' activesupport (3.0.4)
lib/active_support/cache/strategy/local_cache.rb:72:in
call' rack (1.2.2)
lib/rack/lock.rb:11:in block in call'
<internal:prelude>:10:insynchronize'
rack (1.2.2) lib/rack/lock.rb:11:in
call' actionpack (3.0.4)
lib/action_dispatch/middleware/static.rb:30:in
call' railties (3.0.4)
lib/rails/application.rb:168:in call'
railties (3.0.4)
lib/rails/application.rb:77:in
method_missing' railties (3.0.4)
lib/rails/rack/log_tailer.rb:14:in
call' rack (1.2.2)
lib/rack/content_length.rb:13:in
call' rack (1.2.2)
lib/rack/handler/webrick.rb:52:in
service'
/Users/USERNAME_REMOVED/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:111:in
service'
/Users/USERNAME_REMOVED/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:70:in
run'
/Users/USERNAME_REMOVED/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/server.rb:183:in
block in start_thread'
params[:session] doesn't exist
def create
user = User.authenticate(params[:session][:email],
params[:session][:password]) if params[:session]
...
Instead of declaring method authenticate in class << self :
class << self
def authenticate(email, submitted_password)
user = find_by_email(email)
(user && user.has_password?(submitted_password)) ? user : nil
end
end
Try this: def self.authenticate(email, submitted_password). Be careful, you have to declare it out of class << self
In this case you are declaring a class method authenticate and you should able to call it in your controller, in the create method.

Resources