# Action view mutiplication problem and why doesn't method work

**URL:** <https://www.ruby-forum.com/t/action-view-mutiplication-problem-and-why-doesnt-method-work/147379>\
**Category:** Rails\
**Created:** [September 1, 2008, 9:48am UTC](https://www.ruby-forum.com/t/action-view-mutiplication-problem-and-why-doesnt-method-work/147379 "2008-09-01T09:48:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [September 1, 2008, 9:48am UTC](https://www.ruby-forum.com/t/action-view-mutiplication-problem-and-why-doesnt-method-work/147379/1 "2008-09-01T09:48:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [September 1, 2008, 10:00am UTC](https://www.ruby-forum.com/t/action-view-mutiplication-problem-and-why-doesnt-method-work/147379/2 "2008-09-01T10:00:28Z")

</div>

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

🙂

---

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [September 1, 2008, 10:11am UTC](https://www.ruby-forum.com/t/action-view-mutiplication-problem-and-why-doesnt-method-work/147379/3 "2008-09-01T10:11:02Z")

</div>

On Sep 1, 8:48 am, tyliong [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 0xb6960044\>"
> 
> I am putting it in the right place??? i have tried the model but no  
> luck

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

---

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [September 1, 2008, 10:18am UTC](https://www.ruby-forum.com/t/action-view-mutiplication-problem-and-why-doesnt-method-work/147379/4 "2008-09-01T10:18:04Z")

</div>

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?  
On Sep 1, 4:10 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
