1

I am getting an error from a recent change I made using heroku console.

After I apply this:

u = User.where(:email => '[email protected]').first
u.invitation_limit = 10
u.save

I get this error:

ActionView::Template::Error (comparison of String with 0 failed):

On this line of code:

<% if current_user.invitation_limit > 0 %>

invitation_limit is an integer field in the database and the number 10 is clearly an integer, but do I need to use to_i, like this?

u.invitation_limit = 10.to_i

Curious if this is a common thing that I am unaware of.

Please let me know if you know anything about this.

Thanks in advance, Brian

3
  • Hi Brian! In the db/schema.rb for User, is the invitation_limit set as a string or an integer? Commented Sep 27, 2012 at 2:45
  • Hey Jesse. It's set as an integer. Commented Oct 2, 2012 at 0:17
  • I too would like to know more about the root cause of this. Commented Jun 7, 2013 at 0:11

2 Answers 2

1

Just write the following magic command in console: heroku restart and hit 'Enter'.

works like a charm every time when you getting very very weird errors in your logs.

Nowadays Heroku for me is like a an old version of Windows - any problem? just restart it!

Sign up to request clarification or add additional context in comments.

1 Comment

That's too true! If in doubt, restart.
0

My guess would be that when you pull the data out of the database, rails is returning everything as a string value - are you using JSON format? Cause that would read as string values.

I would use this:

<% if current_user.invitation_limit.to_i > 0 %>

1 Comment

Thanks for the reply, Krista. That will probably work to resolve the problem, but it doesn't address the root cause, which is something I'd like to know more about. Interestingly, when the integer is set by a method through a before_save on user, the error does not happen. It's only after I used the console that the error occurred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.