1

Similar problem often occurs when I am using "unless", I thought I must ask about it if probably there is a reason or it may be a fault with rails?

I usually handle it by removing "unless" and making it an "if"

    if package.services.find_by_service_type_id(service_type_id).present?
      package.services.find_by_service_type_id(service_type_id).update_attribute(:total_cost, total) unless service_type_id.nil?
    else
      puts "*"*80
      puts count++
    end
ARK
  • 772
  • 7
  • 21
  • Please notice that the question is about usage of "unless" at the end of second line of code. – ARK Oct 22 '19 at 08:19

1 Answers1

2

Because there's no ++ operator in Ruby. You can use += instead:

puts count += 1

Also:

I thought I must ask about it if probably there is a reason or it may be a fault with rails?

It can't be "a fault with Rails" since Rails is only a web framework, it doesn't alter Ruby's syntax, hence it can't 'cause' syntax error.

Marek Lipka
  • 50,622
  • 7
  • 87
  • 91
  • Ah, I think my question is a stupid one, now. I am going to accept your answer but I am seriously considering removing the question? – ARK Oct 22 '19 at 08:23
  • 2
    I've left questions I felt were much more silly before :) It doesn't matter how bad you think the mistake is, other people will make it too – Mark Oct 22 '19 at 08:28
  • Thanks @Mark, I will leave it here for now but I asked a seemingly naive question before (because I am new here), and everyone down-voted it which made me remove it :-( – ARK Oct 22 '19 at 08:31