【发布时间】:2012-01-07 09:53:35
【问题描述】:
我有模型文章。
迁移文件:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :name
t.string :description
t.string :body
t.string :keyword
t.integer :price
t.integer :count_text
t.integer :total_price
t.timestamps
end
end
end
我有ArticlesController 有两种标准方法new 和create
我做了new.html.erb 文件并使用了表单助手。
但是字段和count_text total_price需要自动生成(price * count_text)
Count_text - 是正文线的大小。
用户在字段正文中输入文本,计算文本然后乘以价格并在确认创建记录之前显示给用户。如何制作?
【问题讨论】:
-
您的问题很难理解,尤其是“But the ..”之后的部分。有(至少)两个方面:在客户端动态计算(不会由 rails 完成),在控制器中计算一些东西(但只有在提交后才有可能)。你能澄清一下你想要什么吗?
-
是的,我想知道如何做到这一点
标签: ruby-on-rails ajax real-time calc