ActiveRecord validation error: saying field is blank even though it isn't

57 views Asked by At

When I create try to create a new ActiveRecord I get the following error:

Failure/Error: @gallery = Gallery.create!(gallery_picture: ["test"], GeneralInfo_id: 1, gallery_title: "test", gallery_description: "test")
     
     ActiveRecord::RecordInvalid:
       Validation failed: Gallery picture can't be blank

This is the schema for the galleries table:

create_table "galleries", id: :serial, force: :cascade do |t|
    t.string "gallery_title"
    t.text "gallery_description"
    t.string "gallery_picture", array: true
    t.float "gallery_totalRate"
    t.integer "gallery_totalRator"
    t.integer "GeneralInfo_id"
    t.string "test_picture", array: true
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "gallery"
    t.text "comments", default: [], array: true
  end

And here is my Gallery Model:


class Gallery < ApplicationRecord
    belongs_to :general_info, optional: true
    has_many :reviews
    has_many :gallery_taggings, dependent: :destroy
    has_many :tagged_users, through: :gallery_taggings, source: :general_info

    validates_presence_of :gallery_title
    validates_presence_of :gallery_description
    validates_presence_of :gallery_picture
    validates_presence_of :GeneralInfo_id
    mount_uploaders :gallery_picture, GalleryUploader

    mount_uploaders :test_picture, GalleryUploader
    has_many :comments

end
    

I don't understand why this error is being raised since the gallery_picture field is not blank. Any help would be much appreciated.

0

There are 0 answers