如何根据另一个字段更改模型中的字段?
问候其他开发商。 我有一个模型候选者。RB,我想使用的2列(uperf_code and conticate_type)。 如果cantidate_type =“ chapter”,我想要gupt_code =“ chp”。 我正在尝试使用after_save做到这一点,但这是用cantixed_type =“ chapter”创建所有新的候选人。 我认为我使用的条件是错误的。请指导我
在候选人中
After_save : chapter_offer
def chapter_offer
If self.candidate_type = "chapter"
self.offer_code = "CHP"
end
end
Greetings fellow developers.
I have a model candidate.rb and there are 2 columns(offer_code and candidate_type) that i want to work with.
I want the offer_code = "CHP" if the candidate_type = "chapter".
I am trying to do this with after_save but this is creating all the new candidates with candidate_type = "chapter".
I think the condition that I have used is wrong. Please guide me
In candidate.rb
After_save : chapter_offer
def chapter_offer
If self.candidate_type = "chapter"
self.offer_code = "CHP"
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用
=
进行比较,而不是==
,如果您做这样的事情会更好
You are using
=
for comparison instead of==
And it will be better if you did something like this