tyliong
2008-Sep-01 07:45 UTC
action view mutiplication problem and why doesn''t method work
I am trying to multiply something in view but what i get is the first parameter without the 2nd parameter being multiplied. <%= product.price*product.quantity %> only gives product.price Secondly I have put this method into the --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tyliong
2008-Sep-01 07:48 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bala kishore pulicherla
2008-Sep-01 07:59 UTC
Re: action view mutiplication problem and why doesn''t method work
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 :) On Mon, Sep 1, 2008 at 1:18 PM, tyliong <tyliong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-01 08:10 UTC
Re: action view mutiplication problem and why doesn''t method work
On Sep 1, 8:48 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > luckNo 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tyliong
2008-Sep-01 08:17 UTC
Re: action view mutiplication problem and why doesn''t method work
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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 1, 8:48 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---