新手问题 请问 edit,update 如何获取另一个 action 上的值?

QueXuQ · 2012年10月17日 · 最后由 help5305fff 回复于 2012年10月18日 · 2066 次阅读

是这样的 一个 edit,和 update 的值。 在一个 form 下的 price 值。 我想求出他进入 edit 上和 update 后的差值。 例如 price 是 10,然后我在 edit 中改为 12,然后点击 update,自然跳到 update 的 action 上,请问怎么可以找到本来的那个 price 值呢?

..用 form 提交?

在你 save 之前,model 里有 price_was

#1 楼 @jjym 恩。对 就是 form url => update do |f| f.input :price (原来是 20,edit 成 30) f.button

#2 楼 @wuwx http://stackoverflow.com/questions/2942162/rails-attribute-changed 原来真的有个_was 值。。。第一次用。谢谢。

匿名 #5 2012年10月18日

这没啥特别的吧 <input type="hidden" value="<%= @product.price%>" name="old_price">

在 update 里,你取 params[:old_price] 就是你原来的 price 啦

你需要增加 html 的基础

或者你在 update 里,find 出来的对象,就是原来的 price 值...

需要 登录 后方可回复, 如果你还没有账号请 注册新账号