I have just started with Ruby and Rails and am still greatly confuse, finding the usual tutorials not much help. What I want to do is take two numbers from my database, multiply them together and display them in a list with a comma for the thousands separator. This would be very easy to do in a spreadsheet, so I assumed it would be easy to do in Ruby on Rails but I can''t work out how. I have a list.rhtml with a code snipet like <td><%=h mytable.send(:value1)*mytable.send(:value2) %></td> which does the multiply, but how do I do the formating? I found this link to some Ruby code that might do this, but where would I put it and how would I use it? http://wiki.rubygarden.org/Ruby/page/show/NumericFormat Thanks Alan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-12 03:48 UTC
Re: Multiply and format with thousands separator
On May 11, 6:43 pm, Alan Curtis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have just started with Ruby and Rails and am still greatly confuse, > finding the usual tutorials not much help. > > What I want to do is take two numbers from my database, multiply them > together and display them in a list with a comma for the thousands > separator. This would be very easy to do in a spreadsheet, so I assumed > it would be easy to do in Ruby on Rails but I can''t work out how. > > I have a list.rhtml with a code snipet like > > <td><%=h mytable.send(:value1)*mytable.send(:value2) %></td> > > which does the multiply, but how do I do the formating? > > I found this link to some Ruby code that might do this, but where would > I put it and how would I use it? > > http://wiki.rubygarden.org/Ruby/page/show/NumericFormat > > Thanks > > Alan > > -- > Posted viahttp://www.ruby-forum.com/.there''s this helper which lets you set the separator and delimiter, i.e. what the comma and period does. http://railsmanual.org/module/ActionView::Helpers::NumberHelper/number_with_delimiter/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> On May 11, 6:43 pm, Alan Curtis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> <td><%=h mytable.send(:value1)*mytable.send(:value2) %></td> >> Alan >> >> -- >> Posted viahttp://www.ruby-forum.com/. > > there''s this helper which lets you set the separator and delimiter, > i.e. what the comma and period does. > > http://railsmanual.org/module/ActionView::Helpers::NumberHelper/number_with_delimiter/Thanks. I put <td><%=h number_with_delimiter(mytable.send(:value1)*mytable.send(:value2)) %></td> in my list.rhtml and that works. As I am new to both Ruby and Rails, I am still getting things straight. I have two follow-up questions, if I may. 1 . Can I do an assignment myvalue=number_with_delimiter(mytable.send(:value1)*mytable.send(:value2)) somewhere and use <td><%=h myvalue %></td> If so, what is the syntax and in which file do I put the assignment? 2. I thought Ruby was OO and used methods. number_with_delimiter looks like a function. Is it? Shouldn''t I be using it as a method? If it''s a method, what is its object? Alan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-12 16:55 UTC
Re: Multiply and format with thousands separator
Alan Curtis wrote:> gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > On May 11, 6:43 pm, Alan Curtis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > >> <td><%=h mytable.send(:value1)*mytable.send(:value2) %></td> > >> Alan > >> > >> -- > >> Posted viahttp://www.ruby-forum.com/. > > > > there''s this helper which lets you set the separator and delimiter, > > i.e. what the comma and period does. > > > > http://railsmanual.org/module/ActionView::Helpers::NumberHelper/number_with_delimiter/ > > Thanks. > > I put > > <td><%=h > number_with_delimiter(mytable.send(:value1)*mytable.send(:value2)) > %></td> in my list.rhtml > and that works. > > As I am new to both Ruby and Rails, I am still getting things straight. > I have two follow-up questions, if I may. > > 1 . Can I do an assignment > > myvalue=number_with_delimiter(mytable.send(:value1)*mytable.send(:value2)) > > somewhere and use > > <td><%=h myvalue %></td> > > If so, what is the syntax and in which file do I put the assignment? > > 2. I thought Ruby was OO and used methods. number_with_delimiter looks > like a function. Is it? Shouldn''t I be using it as a method? If it''s a > method, what is its object? > > Alan > > -- > Posted via http://www.ruby-forum.com/.I think to work with rails, you have to understand mixins, class variables vs. class instnace variables, open classes, topics like that. I recommend David Blacks "Ruby for Rails" book. I don''t have it in front of me, but it covers all of these, and many others, really well, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Alan Curtis wrote: >> > there''s this helper which lets you set the separator and delimiter, >> %></td> in my list.rhtml >> >> -- >> Posted via http://www.ruby-forum.com/. > > I think to work with rails, you have to understand mixins, class > variables vs. class instnace variables, open classes, topics like > that. I recommend David Blacks "Ruby for Rails" book. I don''t have > it in front of me, but it covers all of these, and many others, > really well,Wow. I guess I was sucked in by how easy it was to get started. This sounds like I have to learn a lot of stuff to do anything beyond the mere basics with Ruby on Rails. Thanks anyway. Alan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---