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 8618269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:04:02+00:00 2026-06-12T06:04:02+00:00

I have a very simple configuration for uploading files. I simply want to upload

  • 0

I have a very simple configuration for uploading files. I simply want to upload an image to a database (I know, I know…) with a description. That’s it.

Here is what my model looks like (which I learned from here). Basically, it is exactly the way the example is setup, only with the attr_protected line to work Rails 3.2:

Photo < ActiveRecord::Base
  # note: there is also a :description attribute!!
  attr_protected :file_name, :content_type, :binary_data
  def image_file=(input_data)
    self.file_name input_data.original_filename
    self.content_type = input_data.content_type.chomp
    self.binary_data = input_data.read
  end
end

Here is what my very simple view looks like:

<h1>New Photo</h1>

<%= form_for(@photo) do |f| %>

  <fieldset>
    <legend>Upload a Photo</legend>

    <div class="control-group">
      <label class="control-label">Photo</label>
      <div class="controls">
        <%= f.file_field :image_file %>
      </div>
    </div>

    <div class="control-group">
      <%= f.label :description, class: "control-label" %>
      <div class="controls">
        <%= f.text_field :description, class: "text_field" %>
      </div>
    </div>

    <div class="form-actions">
      <%= f.submit "Upload", class: "btn btn-primary" %>
      <%= link_to "Cancel", photos_path, class: "btn" %>
    </div>
  </fieldset>

<% end %>

And finally (merely for completeness), here is my Create action (simple scaffolding):

def create
  @photo = Photo.new(params[:photo])

  respond_to do |format|
    if @photo.save
      format.html { redirect_to @photo, notice: 'Photo was successfully created.' }
      format.json { render json: @photo, status: :created, location: @photo }
    else
      format.html { render action: "new" }
      format.json { render json: @photo.errors, status: :unprocessable_entity }
    end
  end
end

The idea is that the user will choose a file and type a small description which should post to a ‘Create’ method on the /photos controller. Unfortunately when I click the submit button I get a very vague error that doesn’t give me information about what the real problem is:

ArgumentError in PhotosController#create

wrong number of arguments (1 for 0)
Rails.root: /Users/me/dev/photo-app

Application Trace | Framework Trace | Full Trace
app/models/photo.rb:4:in `image_file='
app/controllers/photos_controller.rb:43:in `new'
app/controllers/photos_controller.rb:43:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"qSjMHgjCDo2ORmTvnujrljfPCj6oekLI9KAz4x5gA7Q=",
 "photo"=>{"image_file"=>#<ActionDispatch::Http::UploadedFile:0x00000101726fd0 @original_filename="SomePic.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"photo[image_file]\"; filename=\"SomePic.jpg\"\r\nContent-Type: image/jpeg\r\n",
 @tempfile=#<File:/var/folders/kc/8hsmx29j3xn2_j_9tsw8bz6w0000gn/T/RackMultipart20121001-52387-lre7zh>>,
 "description"=>"my description"},
 "commit"=>"Upload"}

I’ve looked all over Google and StackOverflow, but nothing seems to match my (very simple) example. Any help would be greatly appreciated!

Thanks in advance!

  • 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-12T06:04:04+00:00Added an answer on June 12, 2026 at 6:04 am

    I took @kiddorails advice and implemented CarrierWave along with the Amazon Web Service. My project required image uploads and I was limited to Heroku. Therefore, I dove in and figured it out. In hind sight, it’s the best solution, but at the time it seemed overkill for my (sample) project application. It was tricky for me (as a ‘non-Ruby on Rails’ developer).

    At the end of the day, I would recommend anybody else who wishes to store images into a database to NOT do that, and do the same thing I did. Learn the right way to do it. 🙂

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

Sidebar

Related Questions

I have a very simple query that is driving me absolutely nuts. Here's the
I have a very simple database. It s a name/value store for various configuration
I have very simple query. I want to make sure that I don't have
I have a very simple .NET commandline application that I want to port to
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
Short: I am looking for a very simple (configuration/maintenance wise) solution, that would allow
We have a database with a very simple schema: CREATE TABLE IF NOT EXISTS
This is going to be very simple I know. I have seen so many
I have a very simple asp.net mvc3 app that uses jquery::getJSON to call into
I have a very simple screen with an UITextField with the default configuration, nothing

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.