Basic Math in Ruby on Rails -
this question simple should embarrassed ask, searches answers came structuring complex math expressions in ror - need on far more basic.
i have rails 4 app creating invoices. each line_item
has price
, units
, , tax
. need multiply price
units
, multiply times tax
if taxable
boolean true , add come total
.
where i'm struggling figuring out how structure these calculations , equally important, place them in code saves db. inclination put them in model, i'm unsure of.
my attempt @ doing myself adding basic function controller:
def create @line_item = lineitem.new(line_item_params) @line_item.invoice_id = @invoice @line_item.total = @line_item.price * @line_item.units respond_to |format| if @line_item.save format.html { redirect_to @line_item, notice: 'line item created.' } format.json { render :show, status: :created, location: @line_item } else format.html { render :new } format.json { render json: @line_item.errors, status: :unprocessable_entity } end end
end
if can show me example, or resources discuss basic math in ruby, i'd appreciate greatly.
i'm not ror developer, think doing these calculations on front-end easier.
other that, these resources found possibly useful:
Comments
Post a Comment