Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:59+00:00 2026-06-17T15:53:59+00:00

I have an Image model with a :text column named image and am unable

  • 0

I have an Image model with a :text column named image and am unable to save the image field using FactoryGirl.

Here are the relevant piece of code:

image_spec.rb:
let(:image) { FactoryGirl.create(:image) }
subject { image }
it { should be_valid }


factories.rb:
factory :image do
    image "123456789.jpg"
end


image.rb:
attr_accessible :image
validates :image, presence: true

When I run the tests I get the error

Failure/Error: let(:image) { FactoryGirl.create(:image) }
 ActiveRecord::RecordInvalid:
   Validation failed: Image can't be blank

for all three of the lines in the image_spec.rb above.

I’ve tried applying How to initialize a column named 'sequence' with FactoryGirl but I couldn’t get it working. (FactoryGirl creations for my other models work fine)

How do I assign to columns that have the same name as their table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:54:00+00:00Added an answer on June 17, 2026 at 3:54 pm

    try this:

    FactoryGirl.define do
      factory :image do |i|
        i.some_attr 'xxx'
        i.image "123456789.jpg"
      end
    end
    

    that way you are actually calling the image= method of the image object, the other way factory girls thinks you are trying to create an association

    (you have really used a confusing name for that column anyway :P, image_path or something like that would be better)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django model with a text field. I'm using a rich text
I'm using ASP.NET MVC and have a model which has an image (byte array)
How can I find an image, depending on the text? I have image model
I need to have an image instead of clickable text and using MVC helpers.
I have an image model with an attribute :description which is a text, formatted
I have the following model, as you can see in the image. alt text
I have a model Image and every image is having description. User can add
In my model I have: has_attached_file :image, :storage => :s3, :styles => { :original
I'm using sorl-thumbnail to get some images to crop. I have a model looking
I have the following model: class Image(db.Model): auction = db.ReferenceProperty(Auction) image = db.BlobProperty() thumb

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.