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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:56:45+00:00 2026-06-13T12:56:45+00:00

Delving into Rails’ upload functionality and actually following this railsguide. I use the following

  • 0

Delving into Rails’ upload functionality and actually following this railsguide.

I use the following code for the upload form:

<%= form_tag({ action: :upload }, multipart: true) do %>
    <%= file_field_tag :picture %>
    <%= submit_tag %>
<% end %>

And this is my upload method:

def upload
    uploaded_io = params[:customer][:picture]     #erroneous line!!
    File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|
      file.write(uploaded_io.read)
    end
    flash[:notice] = "File uploaded successfully!"
    redirect_to root_path
end

I have marked the line which I believe is erroneous in the second code snippet. The upload method is just pasted from the railsguide and I adjusted the params array to [:customer].

When uploading a file I get this error:

undefined method `[]' for nil:NilClass

It refers to the line I marked above.

I also found this other question, but I haven’t figured out yet how that might help me.

What am I doing wrong? Is my form wrong or my controller method? Any help appreciated.

  • 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-13T12:56:46+00:00Added an answer on June 13, 2026 at 12:56 pm

    Try changing to

    params[:picture]
    

    Can always look at the logs to see how the request parameters hash is structured. When you use a form_for in rails, let’s say on a customer object like below. You then get the fields as

    [:customer][:field_name] 
    

    But since you just used the form_tag helper, it’s not encased in another hash:

    <%= form_for @customer do |f| %>
     <%= f.text_field :field_name %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While delving into ruby's nested models I encountered an issue. Consider the following scenario,
This question is about making an architectural choice prior to delving into the details
Im not sure if this can be done, im just delving into templates so
To recreate this behaviour, you need to create a pop-up form with the following
Further delving into the mysteries of R evaluation...This is closely related to my previous
I am delving into the EntityFramework 4 code first of entities approach and I
While delving into some old code I've stumbled upon a function which is used
I am interested in delving into Erlang's C source code and try to understand
I have lately been delving into F# and the new DSL stuff as in
I have recently begun delving into the world that is database programming with C++

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.