Comparison operators do not work (in erb representations)

I'm new to Ruby on Rails, and I'm trying to write more than an expression:

<% if current_member.photo_limit > 5 %> 

a character larger than a character continues to throw an error resulting from an exception. I'm not sure how to fix this?

Edit: this is not the rails, or view, its Ruby design

+6
source share
1 answer

using <% if current_member.photo_limit.to_i> 5%>

the error arises from photo_limit, not passing from the Integer class (guessing its valid string) and, therefore, not having a mixed comparison method / s

For more on this, see: http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/

in particular, you need to mix in Comparable and define the <=> method.

using String.to_i should be fine though ...

+5
source

Source: https://habr.com/ru/post/889041/


All Articles