[英]How to customize strong parameter in rails
i'm a rails newbie and I got a problem. 我是Rails新手,但遇到了问题。 When I user a strong parameter:
当我使用强参数时:
params.require(:project).permit(:project_name, :real_time)
I want to use it do update the project: 我想用它来更新项目:
@project.update_attributes(user_project_params)
but before that, i want to change the value of 但在此之前,我想更改
:real_time
ex: :realtime += 2
please tell me how can i do that? 请告诉我我该怎么做?
Any predefined modifications to the model objects are always done in model. 对模型对象的任何预定义修改总是在模型中完成。
You can write a method in model and call it using callbacks 您可以在模型中编写方法并使用回调进行调用
class Project< ActiveRecord::Base
before_save :update_real_time
private
def update_real_time
self.real_time= self.real_time +2
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.