devise_invitable icon indicating copy to clipboard operation
devise_invitable copied to clipboard

ArgumentError (comparison of String with 0 failed)

Open TheOddLinguist opened this issue 13 years ago • 11 comments

Error's coming from: https://github.com/scambra/devise_invitable/blob/master/lib/devise_invitable/inviter.rb#L18

In development (on a Mac), it seemed to work fine. Deployed to Heroku, and I'm getting this error. Do I have a configuration issue? Or perhaps that value should be cast to an integer before comparison? If so, I can submit a quick pull request if that makes it easier. Thanks either way.

TheOddLinguist avatar Feb 23 '12 08:02 TheOddLinguist

Can you check database? Is invitation_limit an integer?

scambra avatar Feb 23 '12 08:02 scambra

Migration:

t.integer    :invitation_limit, :default => 0

Schema:

t.integer  "invitation_limit", :default => 0

Console:

irb(main):001:0> User.invitation_limit.class
=> Fixnum

irb(main):002:0> User.first.invitation_limit.class
User Load (18.7ms)  SELECT "users".* FROM "users" LIMIT 1
=> Fixnum

Let me know if you need any more info. Thanks.

TheOddLinguist avatar Feb 23 '12 08:02 TheOddLinguist

Do you know user which was inviting? Can you test invitation_limit in that user?

scambra avatar Feb 23 '12 08:02 scambra

I've got 5 set in the initializer, 0 set on all users in db. The plan is to not allow invites unless I set the limit to nil on a given user. I set the 5 since it seemed like you needed a value there for the db value to take effect.

TheOddLinguist avatar Feb 23 '12 08:02 TheOddLinguist

Ok. Is it reproducible? Can you reproduce from the console? calling user.has_invitations_left? or user.invitation_limit

scambra avatar Feb 23 '12 09:02 scambra

Interestingly, it's fine from the console:

irb(main):004:0> User.first.has_invitations_left?
User Load (4.9ms)  SELECT "users".* FROM "users" LIMIT 1
=> false
irb(main):005:0> User.first.invitation_limit
User Load (8.3ms)  SELECT "users".* FROM "users" LIMIT 1
=> 0
irb(main):006:0> User.first.invitation_limit.class
User Load (12.2ms)  SELECT "users".* FROM "users" LIMIT 1
=> Fixnum

But when I try to send an invitation from this user's account, I get this error:

2012-02-23T08:10:23+00:00 app[web.1]: Started POST "/users/invitation" for 98.235.36.57 at 2012-02-23 08:10:23 +0000
2012-02-23T08:10:23+00:00 app[web.1]: 
2012-02-23T08:10:23+00:00 app[web.1]: ArgumentError (comparison of String with 0 failed):
2012-02-23T08:10:23+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/devise_invitable-1.0.0/lib/devise_invitable/inviter.rb:18:in `>'
2012-02-23T08:10:23+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/devise_invitable-1.0.0/lib/devise_invitable/inviter.rb:18:in `has_invitations_left?'
2012-02-23T08:10:23+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/devise_invitable-1.0.0/app/controllers/devise/invitations_controller.rb:55:in `has_invitations_left?'

This isn't an emergency or anything. It's a production environment, but this app is still in development. I was just intrigued since it functioned properly on my laptop in development.

If you think of anything else you'd like me to check, let me know. Otherwise, don't worry about it too much. Haven't seen anyone else with this issue, so I'm guessing it's something about my configuration.

TheOddLinguist avatar Feb 23 '12 09:02 TheOddLinguist

I'm intrigued too. It should never return a string

scambra avatar Feb 23 '12 09:02 scambra

I've faced the same issue,when I run my app on production. Any solution for this ?

kahnachouhan avatar Jun 03 '12 07:06 kahnachouhan

A failing test would be useful to reproduce it and fix it. If you don't know how to write the test or you cannot reproduce it in a test, I would need a sample application to reproduce it.

scambra avatar Jun 05 '12 11:06 scambra

Can someone with this problem write a failing test? Or provide a sample app?

scambra avatar Jan 28 '13 21:01 scambra

FYI, we had the same error only on production and a restart fixed it.

austinwang avatar Feb 01 '13 00:02 austinwang