Rails如何将params从控制器传递到after_save模型中 [英] Rails How to pass params from controller to after_save inside model

查看:104
本文介绍了Rails如何将params从控制器传递到after_save模型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rfq控制器,我正在创建新的或更新现有的Rfqs,当我创建或更新对象被保存时,我想要的是因为我有一些引号params我想用参数中的引号更新line_items表[quote]在保存Rfqs后的quote_price列中

I have a Rfq contoller i am creating new or updating existing Rfqs, when i create or update the object is saved, what i want is as i have number of quotes params i want to update the line_items table with the quotes in params[:quotes] in quote_price column after saving the Rfqs

我知道它很混乱,但是谁应该得到一些提示我想问一下。

i know its confusing, but who are ror-ish should have got some hint wat i want to ask.

推荐答案

如果您尝试在您的 params 模型,你违反了MVC的原则。模型应该独立于争论。如果您尝试执行以下操作:

If you're trying to use the params hash in your model, you are violating principles of MVC. The model should stand alone with arguments. If you are trying to do the following:

# controller
Model.foo

# model
def foo
  params[:bar].reverse!
end

您应该做以下事情:

# controller
Model.foo(params[:bar])

# model
def foo(foobar)
  foobar.reverse!
end

这篇关于Rails如何将params从控制器传递到after_save模型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆