I have an item model. In that model I need to be able to calculate the profit of a product. However, if I just bought that item it obviously has not been purchased yet and the values for `sold_for`, `fees`, and `shipping` will be empty. If there are no values entered I get a `undefined method`-' for nil:NilClass`error. I tried`rescue NoMethodError`, but then it would not calculate the profit. Is there a way to avoid the error and also have my calculation work?

items.rb

```
class Item < ActiveRecord::Base
  def profit_calc
    sold_for - bought_for - fees - shipping
  end

  def self.purchase_total
    sum(:bought_for)
  end

  def self.fee_total
    sum(:fees)
  end

  def self.shipping_total
    sum(:shipping)
  end

  def self.sales_total
    sum(:sold_for)
  end

  def self.profit_total
    sum(:sold_for) - sum(:bought_for) - sum(:fees) - sum(:shipping)
  end

  scope :visible, -> { where(sold: false) }
  scope :sold, -> { where(sold: true) }
end

```

html.erb:

```
<td><%= number_to_currency(item.profit_calc) %></td>

```