мои пользователи могут вводить и создавать цены.Я хотел знать, как сделать так, чтобы при вводе 23,5 пользователь получал вместо него 23.50 или 0.0 получал 0.00.Как добавить к t.decimal или моей цене: десятичную следующую способность?
Спасибо за помощь!
Ответ (: цена с точностью и точностью)
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
моя форма лесов: <% = f.label: цена%><% = f.text_field: price%>
Тогда, на ваш взгляд, укажите number_to_currency (@ model.attribute):
Цена: