0

Ruby code in my view crashes my rails app on heroku. Meanwhile it works in development. I'm using HAML.

    = @sold
    - @sold.each do |x|
      %p lorem

It breaks on the second line - @sold.each do |x| regardless if @sold is equal to nil or if it has a value. Do you guys have any clue as to why?

controller:

  def activity
    @user = current_user 
    @selling = @user.products.where( "quantity != ?", 0 )
    @sold = @user.products.where( "quantity == ?", 0 )
  end

EDIT : Heroku logs says

"HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

2013-10-21T03:21:40.646768+00:00 app[web.1]:     21:           %p one
2013-10-21T03:21:40.646570+00:00 app[web.1]:     20:         - @sold.each do |x|
2013-10-21T03:21:40.646570+00:00 app[web.1]:     17:             %button Status
2013-10-21T03:21:40.646570+00:00 app[web.1]:     18:       %tbody
2013-10-21T03:21:40.646570+00:00 app[web.1]:     19:         = @sold
2013-10-21T03:21:40.646768+00:00 app[web.1]:   app/views/users/activity.html.haml:20:in `_app_views_users_activity_html_haml___1193554036748909609_69954007105480
4
  • What is the type of @sold? Commented Oct 21, 2013 at 3:34
  • Did you confirm the version of Ruby running on Heroku is the same as yours locally? Commented Oct 21, 2013 at 3:38
  • @AlainGoldman: is there any extra content above the HINT line? Please show us the 20 lines above and below this message. Commented Oct 21, 2013 at 3:39
  • ^ yes i did that by stating the version of ruby in my gemfile Commented Oct 21, 2013 at 3:39

1 Answer 1

6

Try changing this line:

@sold = @user.products.where("quantity == ?", 0)

To this:

@sold = @user.products.where(quantity: 0)

I think the problem is because you're trying to use the double equals as a matcher in PostgreSQL, but it does not support that. You should use = if you want to check for equality there.

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

4 Comments

or use nice AR hash syntax, eg. where(quantity: 0)
That was it. That was a phenomenal point thanks!! I'll mark it correct after two minutes. Thanks !!!!
does it support != what if i wanted to check for items still selling would this work ?? @selling = @user.products.where("quantity != ?", 0)
@AlainGoldman: Yes, PostgreSQL understands !=. You might want to spend some time reviewing the documentation and you really really should be developing on top of PostgreSQL if you're going to deploy on PostgreSQL (no, AR will not insulate you from the differences between databases, not even close).

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.