lilipupu pupu lilipupu pupu - 1 year ago 49
Ruby Question

Check a value before saving

I'm trying to implement a condition in my form which say

if cat:(integer)=1 @post.update(father: "lolo")

I'd try put this into my create action, and too into a before_save but is not working. So if you have any ideas to solve this, you're welcome !!

My code :

Option 1 (into the create action)=

if = 1
@cycle.update(father: "lolo")

Option 2 (before_save action )

before_save :check_cat

def check_cat
@cow = self.cow
if @cow.cycles.any?
self.update(father: "lolo")

Answer Source
if = 1

You are using assignment in if operator. Must use comparison. Read this for details:

in short must be

if == 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download