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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:24:57+00:00 2026-06-02T00:24:57+00:00

I am trying to pass parameters using a generic fields_for method. I have a

  • 0

I am trying to pass parameters using a generic fields_for method. I have a form:

<%= form_for @Album do |album| %>
...
<%= fields_for :photo do |photo| %>
  <%= photo.text_field :name %>
  <%= photo.text_area  :description %>
  ...
<% end %>
<% end %>

I was hoping this form would generate photo[name] and photo[description] so that when I submit the form, my controller can do a check if params[:photo] exists… #do something.
The reason I am not using nested forms, is because sometimes these form fields won’t even be used.

The issue is that I am getting is an error for the fields_for :photo line. It says you have a nil object when you didnt expect it! You might have expected an instance of an array.

How can I do this generic fields_for without it being nil?

  • 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-02T00:24:59+00:00Added an answer on June 2, 2026 at 12:24 am

    You’re encountering this problem because there’s no @photo variable defined in your controller. fields_for, just like form_for, is intended to be a wrapper for an existing object. The symbol :photo is being turned into an instance variable, but it’s nil and so that’s why you’re hitting these errors. You can correct this by defining the photo in the controller action:

    @photo = @album.photos.first # if there's an existing photo
    @photo = @album.photos.new # if there's not
    

    If you don’t want to define an object at all, then you’ll need to just use the regular form tags instead of fields_for.

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

Sidebar

Related Questions

I am trying to pass parameters from Visual Studio using VB.net to a Crystal
I am trying to implement the deleting method and pass my parameters for the
I have a web app with a form that I am trying to pass
I'm trying to pass PHP Function parameters using Javascript (not JQuery) AJAX. Do I
I'm trying to pass in an unknown number of parameters (from 1-10) using an
I am trying to pass parameters via URL using: setParams({id:id,model:mod}) , and in the
I'm trying to pass value by using EL expression in get request parameter, but
I'm trying to pass parameters from a PHP middle tier to a java backend
im trying to pass two parameters to a function, i being an int value
I'm trying to pass lists and maps as GET parameters, and I'm wondering if

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.