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

  • SEARCH
  • Home
  • 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 9133349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:28:24+00:00 2026-06-17T08:28:24+00:00

I have an Artwork model with an image attribute where Carrierwave is mounted. While

  • 0

I have an Artwork model with an image attribute where Carrierwave is mounted. While writing controller specs I realized that the image field stays blank, even when I thought I was passing in a file object.

My debug info tells me that the problem is with the image attribute I have CarrierWave mounted on, and not something else. I don’t think I’m passing in the information it needs, but I don’t know what to try.

Here’s the the controller action, with some debug information to identify the problem:

def create
    @artwork = @imageable.artworks.new(params[:artwork])
    logger.debug "Artwork should be valid: #{@artwork.valid?}"
    logger.debug "Errors: #{@artwork.errors.full_messages}"
    if @artwork.save
        flash[:success] = "Artwork created."
        redirect_to [@imageable, :artworks]
    else
        flash[:error] = "Artwork not created."
        render :new
    end
end

In the test log I see this after running my specs:

Processing by ArtworksController#create as HTML
  Parameters: {"artwork"=>{"image"=>"#<File:0x4515480>", "title"=>"Portrait","year"=>"2012", "surface_type"=>"canvas", "size"=>"10 x 10", "price"=>"100.0", "for_sale"=>false, "prints_available"=>false, "notes"=>"extra notes"}, "file"=>"#<File:0x46c6938>", "originals_gallery_id"=>"1"}
[1m[36mOriginalsGallery Load (0.0ms)[0m  [1mSELECT "originals_galleries".* FROM   "originals_galleries" WHERE "originals_galleries"."id" = ? LIMIT 1[0m  [["id", "1"]]
Artwork should be valid: false
Errors: ["Image can't be blank"]

Any thoughts, please? Is there a controller param I’m forgetting to set?

  • 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-17T08:28:25+00:00Added an answer on June 17, 2026 at 8:28 am

    My problem was a more general one: during my tests (with Rspec and FactoryGirl) I was passing in the wrong kind of file object to the controller action. This is the kind of object I was defining for my image attribute:

    FactoryGirl.define do
      factory :artwork do
        image { File.open(File.join(Rails.root, 'spec', 'support', 'sample.gif')) }
        ...other attributes omitted
      end
    end
    

    The above is the setup that Carrierwave docs recommended for FactoryGirl test fixtures. It worked for testing the model and most controller actions, but not for the create action.

    My test logs were telling me that my image attribute was blank, despite passing in this File object. After some searching I found out that you could pass in an instance of Rack::Test::UploadedFile (I think that ActionDispatch::Http::UploadedFile is what’s submitted through the browser(?)).

    So instead of the image attribute being set to File.open(...) in the factory, I set it to Rack::Test::UploadedFile.new(Rails.root.join("spec/support/sample.gif")). My controller specs passed and the file upload was saved to the database.

    I think this helps explain why a lot of people witness successful file uploads in the browser, but not in their tests or validations.

    This post about testing file attachments in Rails 3 really helped.

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

Sidebar

Related Questions

I have an Artwork model that is manipulated only by API endpoints right now.
I have a method in a rails 3 model that parses XML with nokogiri.
I have a simple Python program that gets artwork from MP3 files. But when
I have a client WordPress website that allows users to upload custom artwork from
I have an iPad application that will display a popover using custom artwork. From
i have a bunch of CD's that contain a bunch of artwork. I want
How do I create iTunes Artwork for my app? Currently, I have the default
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I'm working on a flash project that incorporates a lot of artwork done in
I'm building a one page form that will create a model and it's relations.

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.