开发者

Comparison operators not working (in erb views)

开发者 https://www.devze.com 2023-03-08 04:53 出处:网络
I\'m pretty new to Ruby on Rails, and I\'m tryin开发者_Go百科g to write a more than expression: <% if current_member.photo_limit > 5 %>

I'm pretty new to Ruby on Rails, and I'm tryin开发者_Go百科g to write a more than expression:

<% if current_member.photo_limit > 5 %>

the greater than symbol keeps throwing an Exception caught error. I'm not sure how to fix this?

Edit: This isn't rails, or the view, its a Ruby construct


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

the error is from photo_limit not extending from the Integer class (guessing its really a string), and therefore not having the mixed-in comparison method/s

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

specifically you have to mix in Comparable and define the <=> method.

using String.to_i should be fine here though...

0

精彩评论

暂无评论...
验证码 换一张
取 消