我想在控制器中检查没有区分大小写的数据库。如果它不存在我想保存它,否则我想显示已经存在的通知。我的控制器是
def party_order_create
@party_order = PartyOrder.find_by(party_order_params)
if @party_order.present?
flash[:success] = "Party Not Saved"
redirect_to :action => "party_order_new"
else @party_order = PartyOrder.new(party_order_params)
@party_order.save
flash[:success] = "Party Saved"
redirect_to :action => "party_order_new"
end
end`
我的模特是,
validates_uniqueness_of :party_order_list, :case_sensitive => false
它运作正常..但我得到了聚会保存通知.. 请有人帮助我
答案 0 :(得分:0)
def party_order_create
@party_order = PartyOrder.find_by(party_order_params)
if @party_order.present?
flash[:success] = "Party Not Saved"
redirect_to :action => "party_order_new"
else
@party_order = PartyOrder.new(party_order_params)
if @party_order.save
flash[:success] = "Party Saved"
redirect_to :action => "party_order_new"
else
// redirect_to
end
end
end