my users can input and create prices. I wanted to know how to make it so when users input 23.5 they get 23.50 instead or 0.0 they get 0.00. How does one add to the t.decimal or my price:decimal the following ability?
Thank you for the help!
The Answer (:price with scale and precision)
class CreatePrices < ActiveRecord::Migration
def self.up
create_table :prices do |t|
t.string :price_name
t.decimal :price, :precision => 10, :scale => 2
t.date :date
t.timestamps
end
end
def self.down
drop_table :prices
end
end
Schema.rb:
create_table "prices", :force => true do |t|
t.string "price_name"
t.decimal "price", :precision => 10, :scale => 2
t.date "date"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
my scaffolded form:
<%= f.label :price %>
<%= f.text_field :price %>
Then in your view put number_to_currency(@model.attribute):
Price: