If I have a model Department
with columns user_id
and group_id
When the action
tries to save an entry into this model
that already exists, i.e. 1 (user_id), 22 (group_id) already exists, at that time I want to raise a violation. What is the way to do this in rails?
Following is the code I am using to save right now:
if @department.save
flash[:notice] = "Successfully created department."
redirect_to @department
else
render :action => 'new'
end
Department
model
class Department < ActiveRecord::Base
belongs_to :group
belongs_to :user
end