action view mutiplication problem and why doesn't method work

Arggh sorry abouht the above post i accidently sent it without
finihing it.

my second question is that i have put this method in the controller

  def qx(product,price)
    result = product.price * product.quantity
  end

and what i get is "undefined method `qx' for #<ActionView::Base:
0xb6960044>"

I am putting it in the right place??? i have tried the model but no
luck

I hope ur trying to do

in ur controller

def view
@product = Product.find(params[:id])
@total = qx(@product.price,@product.quantity)
end

private
def qx(price,quantity)
return price*quantity

end

:slight_smile:

No you're not. If you want to call the method in the view you need to
put it in a view helper (rails will have created an empty view helper
for you.

Just having it inline in the view file should work though (assuming
what you've got are actually all numbers, not strings or something
like that). At the end of the day I'd probably have this as a method
on product.

Fred

One more question for methods

in my method i have this:

def qx(food)
groceries.name.food
end

in the view i do this

<%= qx(food) %>

but i keep getting "wrong number of arguments (0 for 1)"

i try to do this in view food="food" and food=food but no luck

btw do all methods without "self." need to be in the helper file?

and why can't i multiply 2 ruby records together in the view?