フィールド名custom_linkに一意性の検証を適用しようとしています。しかし、フィールドに同じ値を追加することができます。続き は私のモデルである:一意性検証が機能しない
class Gallery < ActiveRecord::Base
....
validates :custom_link, uniqueness: true
....
end
これは、コントローラの私のコードです:それは働いていない理由
def update
respond_to do |format|
if @gallery.update(gallery_params)
format.html { redirect_to galleries_galleryhome_path(id: params[:id]), notice: 'Gallery was successfully updated.' }
format.json { render :show, status: :ok, location: @gallery }
else
format.html { render :edit }
format.json { render json: @gallery.errors, status: :unprocessable_entity }
end
end end
private:
def gallery_params
params.require(:gallery).permit(:name, :shoot_date, :release_date, :expiration_date, :archive,:gallery_layout_id, :contact_id,:status, :cover_url,:gallery_photo_id, photos_attributes: [:image]).merge(brand_id: current_brand.id,user_id: current_user.id)
end
は考えを取得しません。誰でも助けてくれますか?
:
そして最後に一意性はできますかできませんか? – Zabba
こんにちは、あなたはコントローラコードを共有してください。 –
@Bharat Soni、私のコントローラのコードを共有しました – Vishal