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
<%=h mytable.send(:value1)*mytable.send(:value2) %>
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
On May 11, 6:43 pm, Alan C. [email protected]
wrote:
<%=h mytable.send(:value1)*mytable.send(:value2) %>
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/
[email protected] wrote:
On May 11, 6:43 pm, Alan C. [email protected]
wrote:
<%=h mytable.send(:value1)*mytable.send(:value2) %>
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
<%=h
number_with_delimiter(mytable.send(:value1)*mytable.send(:value2))
%> 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
<%=h myvalue %>
If so, what is the syntax and in which file do I put the assignment?
- 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
Alan C. wrote:
there’s this helper which lets you set the separator and delimiter,
%> 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,
[email protected] wrote:
Alan C. wrote:
there’s this helper which lets you set the separator and delimiter,
%> 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