vendredi 12 février 2016

Custom Validation in Model with Parameter from controller

i have this chunk of codes in my controller

def create
  number = params[:number]
  @color = Colors.new(params[:colors])
  @color.save       
end

and i have this validation in model color.rb

validate :should_be_primary

def should_be_primary
   #validations here
end

I just want the validation should only run when my params[:number] == 1

Note: params[:number] is only a parameter and not a table field.

anyone please help me.

Aucun commentaire:

Enregistrer un commentaire